Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Launch login items via AppleScript to avoid login delays' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Launch login items via AppleScript to avoid login delays
Authored by: Andrew J Freyer on Nov 18, '09 08:37:36AM
This is a great hint. Tried it right away, and I'll be damned if it doesn't work like a charm - can't believe I didn't think of this sooner! :)

Anyway, I changed the script a bit, to be more customizable. Set all apps in "theAppList" to the apps (in order) that you want to launch. "theDelay" is the delay.

Additionally, this will hide the application (flashing its window briefly - if someone can fix this that'd be great), and not cause ANY loss in focus.


set theAppList to {"Things", "Mail"} as list
set theDelay to 1

repeat with currentApp in theAppList
	tell application currentApp to launch
	delay theDelay
	tell application "Finder" to set visible of process currentApp to false
end repeat



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: tedw on Nov 18, '09 09:46:52AM
just a tweak on your script, using a list of records:
set theAppList to {{name:"Things", vis:false}, {name:"Mail", vis:true}}
set theDelay to 1

repeat with currentApp in theAppList
	tell application (name of currentApp) to launch
	delay theDelay
	tell application "Finder" to set visible of process (name of currentApp) to (vis of currentApp)
end repeat
this lets you set visibility on a case-by-case basis

[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: Andrew J Freyer on Nov 18, '09 10:20:44AM

NICE!

I was looking for a way to do this, but I didn't think of nested lists for some reason...



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: Andrew J Freyer on Nov 18, '09 10:28:16AM
Another slight edit:

repeat with currentApp in theAppList
	tell application (name of currentApp) to launch
	delay theDelay
	if (vis of currentApp) then
		tell application "Finder" to set visible of process (name of currentApp) to (vis of currentApp)
	end if
end repeat


[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: snit on Nov 18, '09 12:31:47PM

Curious why the delay is before setting visibility.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: tedw on Nov 18, '09 01:22:17PM

it may not be necessary, but sometimes apps need to be in a certain state before they will handle scripting correctly.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: everkleer80 on Nov 18, '09 01:35:41PM

I'm not sure if this 'certain state' means there needs to be some delay after the window opens, but if not then why not just wait (maybe loop with a delay of .1 or something) until a window is visible for the app and then hide the app (then delay some more if you want)... before Skype had fixed the bug where the hide option in login items wouldn't hide the buddy list, I wrote a script for it that hid the window the way I described. This way the window is only visible for up to .1 seconds instead of up to theDelay seconds.

For windowless apps you could just add a property haswindow:false.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: Andrew J Freyer on Nov 18, '09 02:13:53PM

No, he's right. That's why I put the delay there.

Specifically for "Things" - when launched, if I try to hide it immediately, it is not yet prepared (fully opened) to accept the "hide" instruction.



[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: tedw on Nov 18, '09 01:40:59PM
refining it a bit more:
set theAppList to {{name:"Things", vis:false}, {name:"Mail", vis:true}}
set theDelay to 1

repeat with currentApp in theAppList
	tell application (name of currentApp) to launch
	delay theDelay
	tell application "System Events"
		try
			if background only of process (name of currentApp) is false then
				set visible of process (name of currentApp) to (vis of currentApp)
			end if
		end try
	end tell
end repeat


[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: thyvillageidiot on Nov 18, '09 03:51:16PM
Argh, this is such a good script, but I'm getting an error
Finder got an error: Canít make visiblity of process "/Applications/iTunes.app/Contents/Resources/iTunesHelper.app" into type reference.

Furthermore, it is quite annoying to have the space switch and the window flash temporarily. Any work around yet?

[ Reply to This | # ]
Launch login items via AppleScript to avoid login delays
Authored by: tedw on Nov 18, '09 05:04:51PM

read the comments - some of those issues are addressed.



[ Reply to This | # ]