Last active
March 15, 2023 19:55
-
-
Save n8henrie/af0fdc23f7be21ce9a4a3d0cdad33a09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript -l JavaScript | |
'use strict' | |
const Safari = Application("Safari") | |
const Chrome = Application("Google Chrome") | |
const Brave = Application("Brave Browser") | |
const SystemEvents = Application("System Events") | |
const Firefox = Application("firefox") | |
const DefaultBrowser = Firefox | |
// In order of preference | |
const BROWSERS = [Firefox, Safari, Brave, Chrome] | |
function run() { | |
let processes = SystemEvents.processes | |
if (processes.whose({name: {_equals: DefaultBrowser.name()}}).length > 0) { | |
DefaultBrowser.activate() | |
return | |
} | |
for (var idx in BROWSERS) { | |
let browser = BROWSERS[idx] | |
if (processes.whose({name: {_equals: browser.name()}}).length > 0) { | |
browser.activate() | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment