Since switching from having an iMac and a Macbook Pro to just having a Macbook Pro I've found myself battling to get the configurations setup so that screen layouts etc still work efficiently no matter where I'm sitting. If I'm mobile there's one configuration and if I'm at my desk & connected to my external 27" Apple LED display ... there's another.
I found that the easiest way to do this was to write a fairly simple AppleScript that I can run that asks where I'm sitting and then configures the layout appropriately.
Part 1 - Configure apps lists
set DeskAppsList to {"Thunderbird", "Twitterrific", "Google Chrome", "Dropbox", "Bowtie", "iTunes"}
set MobileAppsList to {"Caffeine", "Watts"}
Those two lines setup two lists. The first is a list of apps to start if sitting at my desk, the second is a list of apps to start if I'm mobile, i.e. away from my desk.
Part 2 - Prompt
set action to display dialog "Please select session type ..." buttons ["Desk", "Mobile", "Cancel"] default button "Desk" if button returned of action is equal to "Desk" then
Those lines display a dialog that asks for a session to be selected and then checks to see which button was pressed.
if (count of items in DeskAppsList) is greater than 0 then repeat with AppName in DeskAppsList tell application AppName to activate end repeat end if
That script snippet goes through all the items in the list of desk apps and starts them sequentially. Obviously this can be easily modified to fit the list of mobile apps.
Part 3 - Configure the dock and network profile
-- configure the dock
tell application "System Events"
tell dock preferences
-- e.g. set properties to {minimize effect:genie, location:bottom, autohide:false, magnification:false, dock size:0.15}
set properties to {dock size:0.25}
end tell
end tell
-- set the network location
do shell script "scselect Desk"
The above script snippet configures the dock for a size that fits my setup but you'll need to change it to fit yours. It then enables a network location I have setup that's called "Desk". I've also got one called "Mobile" that is used for when I'm ... wait for it ... mobile. :-)
In case you're wondering, I have different network locations because each one contains the relevant network adapter. Without changing locations, Parallels complains about missing network adapters.
Part 4 - Global apps
set GlobalAppsList to {"Dropbox", "Divvy"}
That sets up a list of apps that are run no matter where I'm sitting. The same script snippet above that starts the desk apps is used to start the global apps but modified to reference the global apps list.
Part 5 - Hide everything
-- hide everything tell application "Finder" activate set frontmost to true set visible of every process whose visible is true and name is not "Finder" to false end tell
Because I'm picky about how tidy things are (OCD-ish, almost ... lol) I then like to tell the Finder to hide everything. That way my desktop is tidy but all the apps I need are up and running. The script snippet above does exactly that.
Does it work?
Yep, sure does. Now all I have to do is run the session manager script, select where I'm sitting and everything is taken care of automatically.
Played