System Events' Login Items Suite

Does anyone know the syntax for deleting an entry in login items using terms from System Events? (or is it only possible to delete the last one)?

Hi,

Reference it by name.

set myItem to "Item to remove"
tell application "System Events"
	delete (login items whose name is myItem)
end tell

Best wishes

John M

Hi, Adam.

Just testing quickly, I can delete login items individually by name or (similarly to John M) by name filter.

tell application "System Events"
	delete login item "Unwanted item"
	delete login items whose name contains "Zap"
end tell

The syntax for adding an item seems to be:

tell application "System Events"
	make new login item at end of login items with properties {path: loginItem}
end tell

The path property can be specified as a POSIX path, an alias, or a file specification, but not as an HFS path. It’s returned as a POSIX path. I haven’t succeeded in setting or reading the hidden property by script.

You’ll discover, however, that the deletion methods only work if the item is last, that you can’t delete an intermediate item by name or index number, and that in the creation of an item whether you put:

make new login item at end of login items with properties {path: loginItem} -- OR 
make new login item at beginning of login items with properties {path: loginItem}

you get the application added at the end of the array.

Hidden doesn’t work for me either.

Clearly, if you wanted to change the order of login items in a script, you’d have to get all the refs from the current list, delete them from the bottom up, rearrange the list to suit, load them all up again, and if you wanted a particular item hidden, there’s no way just now short of GUI scripting or using plist buddy in shell scripts. You can read defaults to see the list in Preferences, but then it would be incumbent on you to provide the ‘data’ section if you wanted to rewrite the list there with a defaults write statement. Ugly.

Hi, Adam.

I’m seeing some of that, but not all. I can (in OS 10.4.7, System Events 1.3.1) delete any login item, by name, by index, by filter, individually, severally, or en masse. I can’t however create login items anywhere but at the end of the list. Only at beginning and at end appear to work at all and they both have the same effect. Similarly, I can’t drag items around in the Accounts/Login Items pane of System Preferences to change their loading order, which I can on my Jaguar Machine and, according to the Help file, is supposed to be possible in Tiger too. As we’ve both noted, the hidden property of a login item isn’t settable or gettable by script.

It’s very interesting that on similar systems, we’re not only both seeing problems but different ones… :confused:

So can I delete any item by all means now. I must have screwed up in an earlier test (which I didn’t keep). What I had done was to get the name of every login item and then refer to the one I wanted by it’s position in that list so I dropped some ball in that process, didn’t get any error message, but didn’t get a result either. I wonder if it matters how long ago the item was added (i.e., whether it had just been added from a script)? Haven’t explored that.

Another interesting item - it doesn’t seem to matter that the Accounts Preferences, including login items pane is locked.

Some afterthoughts on the topic:
Apple’s implementation of login items fires them almost instantly, resulting in an overkill of system load, finishing their launch at random order.
One could argue what that load order really is about (as opposed to Classic extensions…!?)
Some login items (scripts) might depend on each other, leading to unpredictable results.

For these reasons my system only has a few really vital login items.
The rest of them go in a “Delayed Startup Items” folder in my ~Library, and will only load after a certain period of little system activity, with a couple of seconds in between.

This allows for a lean and responsive system if necessary.
It has a true load order, is much more scriptable & configurable…for different locations, of times of the day etc. than the Accounts prefpane is.

As it happens, Eelco, so do mine. There are a bunch of daemons that start up, and my Delayed_Start script.app reads aliases from a Startup Delayed folder in my home folder (so I don’t have to change the script) and gets them going in a controlled manner with appropriate delays.

Without this, because I have a lot of memory and leave a lot running, I wasn’t even getting a Finder promptly, particularly because apps like QuickSilver and FastScripts do searches, gmail Notification calls home, SOHO notes backs up it’s database, Timbuktu registers my IP Address with their server, and Eudora is fetching mail. Much better to parcel them out in time and have the use of several immediately.

For a lean system, I just change the name of the Delayed_Start folder.