Created
February 26, 2015 15:33
-
-
Save bland-industries/85371b38c692460b46a1 to your computer and use it in GitHub Desktop.
Applescript to place specific window at full screen when there are multiple monitors. Works with some caveats.
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
set duetApps to {"Mail", "HipChat", "Console", "iTerm"} | |
set laptopApps to {"Safari", "Google Chrome", "Tower"} | |
set topApps to {"Sublime"} | |
-- toggle full screen | |
on toggleFullScreen() | |
set isFullScreenAfter to false | |
tell application "System Events" | |
try | |
tell front window of (first process whose frontmost is true) | |
set isFullScreen to get value of attribute "AXFullScreen" | |
--log isFullScreen | |
set isFullScreenAfter to not isFullScreen | |
set value of attribute "AXFullScreen" to isFullScreenAfter | |
end tell | |
end try | |
end tell | |
return isFullScreenAfter | |
end toggleFullScreen | |
-- turns app fullscreen off | |
on fullScreenOff(theApp) | |
tell application theApp | |
delay 3 | |
activate | |
delay 3 | |
end tell | |
tell application "System Events" | |
try | |
tell front window of (first process whose frontmost is true) | |
set isFullScreen to get value of attribute "AXFullScreen" | |
--log isFullScreen | |
if isFullScreen is true then | |
set value of attribute "AXFullScreen" to false | |
end if | |
end tell | |
end try | |
end tell | |
end fullScreenOff | |
-- turns app to fullscreen | |
on fullScreenOn(theApp) | |
tell application theApp | |
delay 3 | |
activate | |
delay 3 | |
end tell | |
tell application "System Events" | |
try | |
tell front window of (first process whose frontmost is true) | |
set isFullScreen to get value of attribute "AXFullScreen" | |
--log isFullScreen | |
if isFullScreen is false then | |
set value of attribute "AXFullScreen" to true | |
end if | |
end tell | |
end try | |
end tell | |
end fullScreenOn | |
-- starts an app if not running | |
on startApp(theApp) | |
if application theApp is not running then | |
tell application theApp to launch | |
end if | |
end startApp | |
-- quits an app if running | |
on stopApp(theApp) | |
if application theApp is running then | |
tell application theApp to quit | |
end if | |
end stopApp | |
-- restarts the app | |
on restartTheAppForError(theApp) | |
tell application theApp to quit | |
delay 2 | |
tell application theApp to launch | |
delay 3 | |
end restartTheAppForError | |
-- moves the application to the coordinates | |
on moveApplication(theApp, x, y) | |
tell application "System Events" | |
try | |
set position of first window of application process theApp to {x, y} | |
on error errorText | |
log errorText | |
if ((theApp as string) is equal to "Safari") then | |
tell application "Safari" to open location "http://www.bwata.com/" | |
else | |
tell application theApp to quit | |
delay 2 | |
tell application theApp to launch | |
delay 3 | |
tell application theApp to activate | |
set position of first window of application process theApp to {x, y} | |
end if | |
end try | |
end tell | |
end moveApplication | |
on prepConsole() | |
if application "Console" is not running then | |
do shell script "open -a Console /Applications/MAMP/logs/php_error.log" | |
else | |
fullScreenOff("Console") | |
end if | |
end prepConsole | |
-- gets an app ready to work on | |
-- starts if not running | |
-- makes sure it is not fullscreen already | |
on prepAppForAction(theApp) | |
if application theApp is not running then | |
tell application theApp to launch | |
else | |
fullScreenOff(theApp) | |
end if | |
end prepAppForAction | |
-- Runs the main process on the list. | |
on startForScreen(appList, x, y) | |
-- move apps to location | |
repeat with anApp in appList | |
if ((anApp as string) is equal to "Console") then | |
log anApp | |
prepConsole() | |
else | |
prepAppForAction(anApp) | |
end if | |
end repeat | |
-- move apps to location | |
repeat with anApp in appList | |
moveApplication(anApp, x, y) | |
end repeat | |
-- make apps go full screen | |
repeat with anApp in appList | |
if ((anApp as string) is equal to "Sequel Pro") then | |
activate | |
delay 2 | |
tell application "System Events" to keystroke "f" using {command down, control down} | |
else | |
fullScreenOn(anApp) | |
end if | |
delay 2 | |
end repeat | |
end startForScreen | |
startForScreen(duetApps, 2000, 900) | |
startForScreen(laptopApps, 100, 1500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment