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


Click here to return to the 'Some improvements' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Some improvements
Authored by: nstanger on Dec 13, '01 11:40:34PM
I like this script, but after playing around with it for a little while I found a couple of things that could do with improving. First, the standard Login Items launches everything in the background, which looks much nicer (well, to me anyway). Second, if you rename the aliases (e.g., to set the launching order), process hiding no longer works because the script uses the alias name rather than the name of the original item. Actually, it's also just occured to me that the second one would also prevent you from "hiding" documents. (hack, hack :) Here's an updated version of the script that fixes these:
property pPathToLoginItemsFolder : "" -- The script will set this value.
set loginItemsList to {} -- The script will set this value.
set interLaunchDelay to 5 -- Seconds between launching applications. Feel free to fiddle with this one.
tell application "Finder"
set pPathToLoginItemsFolder to ((container of (path to me) as alias) as text) & "Login Items:"
set loginItemsList to every alias file of folder pPathToLoginItemsFolder
repeat with i in loginItemsList
delay interLaunchDelay

-- Getting the original item of the alias allows us to have aliases with different names from
-- the original items. If we don't do this, it screws up hiding processes below because the
-- process name doesn't match the item name.
set originalItem to original item of i

-- It looks nicer if applications open in the background without coming to the front.
-- Using "open" won't do this, but "launch application" will. However, we can't just use
-- "launch application" for everything because that doesn't let us include documents
-- in the login items. We therefore need to check first whether we're dealing with an
-- application file.
if (class of originalItem is application file) then
-- Odd: "launch application" doesn't work without the "tell me", don't know why.
-- We convert originalItem to a string to get the full path to the application (see
-- http://www.applescriptsourcebook.com/tips/launchbycreator.html for an
-- explanation).
tell me to launch application (originalItem as string)

-- Hide those processes that should be.
if (comment of i is "hide") then
set visible of process ((displayed name of originalItem) as text) to false
end if
else -- Not an application, so just open it.
open originalItem

-- Hide those processes that should be.
if (comment of i is "hide") then
set appName to (displayed name of application file id (creator type of originalItem)) as text
set visible of process appName to false
end if
end if
end repeat
end tell
I haven't tested it extensively, but it appears to do the job. Hope you find it useful!

[ Reply to This | # ]
Some improvements
Authored by: thatch on Dec 19, '01 03:15:32AM

I had some problems with another applescript login item as well as some problems with other user accounts with this tip.

An applescript I had made for moving my browser cache to the trash on login stayed open and became unresponsive when it was a run only script so I had to put it into the regular login items together with this tip script.

When I tried to use this setup in other user accounts, it wouldn't run because of a certain login item called Cookie Dog Login which is kept in ~/Library/Preferences and is listed as a document not an application. It is also in reality a carbon app. The reason it doesn't work is because it doesn't have the correct permissions being another user account.

But I do like the way this tip works for my admin account. I set the time variable to only one second and it works just fine. It's certainly better than having all the login items launch at once. And you can still control the order they launch too.



[ Reply to This | # ]
Some improvements
Authored by: charlau on Mar 13, '10 08:29:25AM
Your script's great, thanks! I started with it, adding growl notifications. so here it is: (Took out the comments to not be repetitive here. I also took out the delay. One thing I'm not sure about is how to get the path for the grolwhelper - here it's hardcoded).
property pPathToLoginItemsFolder : "" -- The script will set this value.
set loginItemsList to {} -- The script will set this value.

setupGrowl()

tell application "Finder"
	set pPathToLoginItemsFolder to ((container of (path to me) as alias) as text) & "Login Items:"
	set loginItemsList to every alias file of folder pPathToLoginItemsFolder
end tell

repeat with i in loginItemsList
	
	tell application "Finder"

		set originalItem to original item of i
		
		if (class of originalItem is application file) then
			tell me to launch application (originalItem as string)
			
			if (comment of i is "hide") then
				set visible of process ((displayed name of originalItem) as text) to false
			end if
		else
			open originalItem
			
			if (comment of i is "hide") then
				set appName to  
				(displayed name of application file id (creator type of originalItem)) as text

				set visible of process appName to false
			end if
		end if
	end tell
	
	set justAppName to getAppName(originalItem as string)
	
	tell application "GrowlHelperApp"
		notify with name 
			"Program started" title 
			"The following program launched" description justAppName 
			application name 
			"Custom login items" icon of application justAppName
	end tell
	
end repeat


on setupGrowl()
	
	tell application "System Events"
		set isRunning to 
			(count of (every process whose name is "GrowlHelperApp")) > 0
	end tell
	
	if (isRunning = 0) then
		open application  
"Macintosh HD:Library:PreferencePanes:Growl.prefPane:Contents:Resources:GrowlHelperApp.app"
		delay 2
	end if
	
	
	tell application "GrowlHelperApp"

		set the allNotificationsList to {"Program started"}
		
		set the enabledNotificationsList to {"Program started"}
		
		register as application 
			"Custom login items" all notifications allNotificationsList 
			default notifications enabledNotificationsList 
			icon of application "Script Editor"
		
	end tell
	
end setupGrowl

on getAppName(thePath)
	
	set oldDelims to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to {":"}
		set withExt to the last text item in (thePath as string) as string
		set AppleScript's text item delimiters to {"."}
		set withoutExt to the first text item in withExt as string
		set AppleScript's text item delimiters to oldDelims
		return withoutExt
	on error
		set AppleScript's text item delimiters to oldDelims
	end try
	
end getAppName



[ Reply to This | # ]