I need to change a theme using a script for Mojave, Alfred and Sourcetree. I've already successfully done this with Mojave and Alfred using this script:
var alfredLightTheme = "Alfred"
var alfredDarkTheme = "Alfred Dark"
function run(args) {
args = args ? args : []
var systemEvents = Application("System Events")
var alfred = Application("Alfred 3")
if (args && args == 'dark') {
systemEvents.appearancePreferences.darkMode = true
alfred.setTheme(alfredDarkTheme)
} else if (args && args == 'light') {
systemEvents.appearancePreferences.darkMode = false
alfred.setTheme(alfredLightTheme)
} else {
systemEvents.appearancePreferences.darkMode = !systemEvents.appearancePreferences.darkMode()
alfred.setTheme(systemEvents.appearancePreferences.darkMode() ? alfredDarkTheme : alfredLightTheme)
}
}
For Sourcetree it seems I need to click the menu items but how can I do that?
Best Answer
Since the OP is tagged with both AppleScript and JavaScript, and are two entirely separate languages, and it was not explicitly and specifically stated that the solution had to be only in JavaScript, here it some code that should work. I say "should work", because it does work on the applications tested on, but I do not have Sourcetree installed to test explicitly and specifically with it.
AppleScript code:
Note: The value of the
delay
command may need to be adjusted for your system.JavaScript code:
Note: The JavaScript code comes from jxaClickAppSubMenuItem.applescript by bumaociyuan and was forked from RobTrew/jxaClickAppSubMenuItem.applescript.