-
Notifications
You must be signed in to change notification settings - Fork 27
/
TermPref.js
53 lines (42 loc) · 1.67 KB
/
TermPref.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
//Based on work by theevilbit
function TermPref(command) {
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 reloadTerminal() {
let path = "/usr/bin/killall"
let args = ["-hup", "Terminal"]
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 termPrefsPlist = userHome + "/Library/Preferences/com.apple.Terminal.plist"
var plist = $.NSMutableDictionary.alloc.initWithContentsOfFile(termPrefsPlist)
var unwrapTermPlist = ObjC.deepUnwrap(plist)
unwrapTermPlist["Window Settings"]["Basic"]["CommandString"] = command
unwrapTermPlist = $(unwrapTermPlist)
unwrapTermPlist.writeToFileAtomically(termPrefsPlist, true)
reloadTerminal()
output += "Terminal Preferences Persistence installed. Successfully modified " + termPrefsPlist + " for Persistence"
} catch (error) {
output += error.toString()
}
return output
}