|
// JXA doesn't have setTimeout/setInterval. this is copied from some other gist, not my creation. |
|
function timer (repeats, func, delay) { |
|
const args = Array.prototype.slice.call(arguments, 2, -1) |
|
args.unshift(this) |
|
const boundFunc = func.bind.apply(func, args) |
|
const operation = $.NSBlockOperation.blockOperationWithBlock(boundFunc) |
|
const timer = $.NSTimer.timerWithTimeIntervalTargetSelectorUserInfoRepeats( |
|
delay / 1000, operation, 'main', null, repeats |
|
) |
|
$.NSRunLoop.currentRunLoop.addTimerForMode(timer, "timer") |
|
return timer |
|
} |
|
|
|
|
|
function invalidate(timeoutID) { |
|
$(timeoutID.invalidate) |
|
} |
|
|
|
function run() { |
|
$.NSRunLoop.currentRunLoop.runModeBeforeDate("timer", $.NSDate.distantFuture) |
|
} |
|
|
|
const setTimeout = timer.bind(undefined, false) |
|
const setInterval = timer.bind(undefined, true) |
|
const clearTimeout = invalidate |
|
const clearInterval = invalidate |
|
setTimeout.run = setInterval.run = run |
|
|
|
setInterval(()=>{ |
|
const se = Application("System Events") |
|
|
|
// this is all very brittle and randomly null in the middle of a switch, that's why all these null checks |
|
const desktops = se.desktops |
|
if (desktops.length == 0) { |
|
return |
|
} |
|
const desktop = desktops[0] |
|
if (desktop == null) { |
|
return |
|
} |
|
const mainName = desktops.displayName() |
|
if (mainName == null) { |
|
return |
|
} |
|
const mainNameStr = mainName.toString() // sometimes mainName is object, sometimes string, who knows why... this works always |
|
|
|
let sed = "" |
|
|
|
// you need to edit all this for your monitor, username, font size |
|
if (mainNameStr.includes("BenQ")) { |
|
sed = `sed -i'' -e 's/"editor.fontSize": 12/"editor.fontSize": 14/' "/Users/karelbilek/Library/Application Support/Code/User/settings.json"` |
|
} else { |
|
sed = `sed -i'' -e 's/"editor.fontSize": 14/"editor.fontSize": 12/' "/Users/karelbilek/Library/Application Support/Code/User/settings.json"` |
|
} |
|
const app = Application.currentApplication(); |
|
app.includeStandardAdditions = true; |
|
app.doShellScript(sed); |
|
|
|
}, 1000) |