-
Notifications
You must be signed in to change notification settings - Fork 27
/
ScreenSaverPersist.js
68 lines (57 loc) · 2.17 KB
/
ScreenSaverPersist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function ScreenSaverPersist(SaverName) {
ObjC.import('Foundation')
ObjC.import("Cocoa")
ObjC.import('stdlib')
let currentApp = Application.currentApplication();
currentApp.includeStandardAdditions = true;
let userHome = $.getenv('HOME')
var output = ""
try{
function listDirectory(strPath) {
var fm = $.NSFileManager.defaultManager;
return ObjC.unwrap(
fm.contentsOfDirectoryAtPathError($(strPath)
.stringByExpandingTildeInPath, null))
.map(ObjC.unwrap);
}
function reloadCfprefsd() {
let path = "/usr/bin/killall"
let args = ["-hup","cfprefsd"]
var pipe = $.NSPipe.pipe;
var file = pipe.fileHandleForReading;
var task = $.NSTask.alloc.init;
task.launchPath = path;
task.arguments = args;
task.standardOutput = pipe;
task.standardError = pipe;
task.launch;
}
var byHostPrefsDirectory = userHome + "/Library/Preferences/ByHost/"
var enumerateFolderContents = listDirectory(byHostPrefsDirectory)
var screenSaverplistPath = ""
for (key in enumerateFolderContents){
if (enumerateFolderContents[key].includes("com.apple.screensaver") == true ) {
screenSaverplistPath = enumerateFolderContents[key]
}
}
var screenPlist = byHostPrefsDirectory + screenSaverplistPath
var plist = $.NSMutableDictionary.alloc.initWithContentsOfFile(screenPlist)
var unwrapScreenPlist = ObjC.deepUnwrap(plist)
//Set the plist values
unwrapScreenPlist["CleanExit"] = "YES"
unwrapScreenPlist["PrefsVersion"] = 100
unwrapScreenPlist["showClock"] = "NO"
unwrapScreenPlist["idleTime"] = 60
unwrapScreenPlist["moduleDict"]["moduleName"] = SaverName
unwrapScreenPlist["moduleDict"]["path"] = userHome + "/Library/Screen Savers/" + SaverName
unwrapScreenPlist["tokenRemovalAction"] = 0
//save plist
unwrapScreenPlist = $(unwrapScreenPlist)
unwrapScreenPlist.writeToFileAtomically(screenPlist, true)
reloadCfprefsd()
output += "Screen Saver Persistence installed. Successfully modified " + screenPlist + " for Persistence"
}catch(error){
output += error.toString()
}
return output
}