Skip to content

Instantly share code, notes, and snippets.

@mitchellh
Created September 22, 2009 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchellh/190859 to your computer and use it in GitHub Desktop.
Save mitchellh/190859 to your computer and use it in GitHub Desktop.
-- Startupper
-- By Mitchell Hashimoto
--
-- A startup script tailored for my own personal use
-- to startup all my applications and set their proper
-- size based on the screen dimension (which changes
-- depending on if my laptop is connected to my 24"
-- monitor or not)
set _scriptName to "AppleScript: Startupper"
-- Setup Growl
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to {"Screen Size Notification", "End Notification"}
set the enabledNotificationsList to {"Screen Size Notification", "End Notification"}
-- Register with Growl
register as application ¬
_scriptName all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Script Editor"
end tell
-- Get Screen Dimensions
tell application "Finder"
set _b to get the bounds of window of desktop
set desktopWidth to item 3 of _b
set desktopHeight to item 4 of _b
end tell
-- Notify what screen dimensions were detected
tell application "GrowlHelperApp" to notify with name ¬
"Screen Size Notification" title ¬
"Startupper" description ¬
"Setting up system for size: " & desktopWidth & "x" & desktopHeight application name _scriptName
-- Set proper bounds based on dimensions or exit
-- if we can't handle them
if desktopWidth = 1920 and desktopHeight = 1080 then
set _safariBounds to {42, 22, 1883, 1076}
set _iTunesBounds to {52, 51, 1593, 1030}
set _iTermBounds to {948, 22, 1834, 1064}
set _adiumContactsBounds to {0, 22, 263, 1080}
set _adiumChatBounds to {629, 169, 1355, 676}
else if desktopWidth = 1280 and desktopHeight = 1024 then
-- laptop dimensions
else
display alert "Unknown Screen Size! Can't setup!"
return
end if
-- Application setup
tell application "Safari"
activate
set the bounds of the first window to _safariBounds
end tell
tell application "iTunes"
activate
set the bounds of the first window to _iTunesBounds
end tell
tell application "iTerm"
activate
set the bounds of the first window to _iTermBounds
end tell
tell application "Adium"
activate
-- We try to set the contacts window size but have to
-- wait for it to actually load up. We try for about
-- 1 minute.
repeat 10 times
set windowFound to false
-- There HAS to be a better way to do this search.
-- set bounds of window whose name is "Contacts" did
-- NOT work. Why?
set adiumWindows to every window
repeat with adiumWindow in adiumWindows
get bounds of adiumWindow
if name of adiumWindow = "Contacts" then
set bounds of adiumWindow to _adiumContactsBounds
set windowFound to true
exit repeat
end if
end repeat
if windowFound then exit repeat
delay 5
end repeat
set bounds of every chat window to _adiumChatBounds
end tell
-- Go back to space #1. This must be set in your spaces system
-- preference.
tell application "System Events" to keystroke "1" using control down
-- Notify completion
tell application "GrowlHelperApp" to notify with name ¬
"End Notification" title ¬
"Startupper" description ¬
"All application startup completed." application name _scriptName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment