Create a gist now

Instantly share code, notes, and snippets.

Applescript used to change application preferences and application geometry based upon a screen resolution.
Overview
--------
This file is invoked when switching from a standalone Macbook Pro display to a Apple Cinema display.
Originally, the only problem I was trying to solve was to move my dock from the side of the screen to
the bottom (which it does), but then after diving deeper in to the Applescript API's, it became obvious
to me that there was no limit to what I can configure.
Details
-------
The flow of the script is as follows:
-It obtains the current screen resolution
-Based upon that, it configures Dock and Webkit
Future
------
As I find more things that are configured based upon my screen resolution, I will add them to this script.
Please feel free to fork and make it your own.
-- Obtain current resolution
tell application "Finder"
set screenSize to bounds of window of desktop
set screenWidth to item 3 of screenSize
set screenHeight to item 4 of screenSize
--display dialog "Screen resolution: " & screenWidth & " X " & screenHeight & " " & screenSize as Unicode text
end tell
-- Configure the Dock based upon the current resolution
if screenWidth is less than 1900 then
tell application "System Events"
tell dock preferences
--get properties
set properties to {minimize effect:genie, magnification size:0.669312179089, dock size:0.0, autohide:false, animate:true, magnification:true, screen edge:left}
end tell
end tell
tell application "WebKit"
set the properties of front window to {bounds:{71, 22, 1350, 893}}
--get properties of front window
end tell
else
tell application "System Events"
tell dock preferences
set properties to {minimize effect:genie, magnification size:0.632275104523, dock size:0.25925925374, autohide:false, animate:true, magnification:true, screen edge:bottom}
end tell
end tell
tell application "WebKit"
set the properties of front window to {bounds:{230, 59, 1612, 1050}}
--get properties of front window
end tell
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment