I am working on a script, saved as an application, that checks the name of the startup disk then, if it’s my internal drive, starts apps in sequence to reduce load, put menu items in my preferred order, and make sure important (to me) apps are started.
If the startup disk is one of my clones, I probably won’t want those apps running, but, just in case, I put in an alert - giving up after 5 seconds - so I could choose to continue. But it flashes for a fraction of a second. Giving up after 10 seconds gives me about 2 seconds (using the “one Mississippi” method of timing) and 13 gives me about 5. If I run the application after login is complete, it gives up after the correct delay.
Could somebody explain why this is happening? I am, as usual, working on this in the middle of the night so my apologies if I am missing something obvious.
thanks
j
EDIT: This morning I discovered that the menu items check causes a hang when logging in after a restart. It works fine if I log out, then in, without a restart, so I guess I have more to figure out.
property menuItems : {"AirPort Menu Extra", missing value, "iChat menu extra", "AppleScript menu extra", "battery menu extra", "user menu extra"} --missing value is screen lock
property scriptDisk : "Macintosh HD"
property appList1 : {"Hey Folders!", "Meteorologist", "Google Notifier", "ClamXavSentry", "Alarm Clock", "Butler", "Edgies"}
property appList2 : {"BackTrack", "Email Backup Pro", "ClamXav"}
(* Wait for Menu Items before continuing*)
(*Borrowed from http://www.macosxhints.com/article.php?story=20060925214542457*)
tell application "System Events"
tell process "SystemUIServer"
repeat until value of attribute "AXDescription" of menu bar items of menu bar 1 is menuItems
delay 0.1
end repeat
end tell
end tell
(*Check Startup Disk before continuing*)
tell application "Finder"
set bootDisk to (get name of startup disk)
if bootDisk is not scriptDisk then
set runScript to button returned of (display alert return & "Startup script cancelled because boot volume is" & return & "\"" & (get name of startup disk) & "\"" message "Run startup script" & space & "for" & space & "\"" & bootDisk & "\"" & space & "?" buttons {"Yes", "No"} default button "No" giving up after 13)
if runScript is "yes" then
my runMyScript()
end if
else
my runMyScript()
end if
end tell
on runMyScript()
repeat with anApp in appList1
tell application anApp to activate
delay 1.25
end repeat
delay 5
tell application "Finder"
set {d1, d2, d3, d4} to (desktop's window's bounds)
set margins to {d1 + 22, d2 + 44, d3 - 22, d4 - 22}
end tell
tell application "Mail"
activate
repeat until window 1 exists
delay 0.1
end repeat
set bounds of window 1 to margins
close window 1
end tell
repeat with anApp in appList2
tell application anApp
activate
tell application "System Events"
repeat until exists process anApp
delay 0.01
end repeat
tell process anApp to set visible to false
end tell
end tell
end repeat
tell application "Finder" to activate
end runMyScript