Last active
August 29, 2015 14:17
-
-
Save xcv58/3a140fb77d3c63767b8d 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
global foundCount | |
global hideCount | |
global frontmostCount | |
on toggle(appPath) | |
if application appPath is running then | |
set foundCount to foundCount + 1 | |
if frontmost of application appPath then | |
if hideCount > 0 then return | |
set hideCount to hideCount + 1 | |
tell application "System Events" | |
set frontProcess to first process whose frontmost is true | |
set visible of frontProcess to false | |
end tell | |
else | |
set frontmostCount to frontmostCount + 1 | |
tell application appPath to activate | |
tell application appPath | |
if windows is {} then reopen | |
end tell | |
end if | |
end if | |
end toggle | |
on run argv | |
set hideCount to 0 | |
set foundCount to 0 | |
set frontmostCount to 0 | |
repeat with arg in argv | |
toggle(arg) | |
if frontmostCount > 0 then exit repeat | |
end repeat | |
if foundCount is 0 then tell application (item 1 of argv) to activate | |
return 0 | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run
Follow application path (prefer) / id / name
This command:
will toggle Chrome first, if Chrome is not running, then try to toggle Safari. If Safari is not running too, it will open Chrome.