7

I have seen a few applications with mixed reviews that will allow a user to change the order of startup items. I would simply prefer the "bare metal" method and stick to using the shell or the Open Directory / netinfo editor to do this. I realize that this isn't controlled via launchd so what is the mechanism and where is the preference location for app startup definition?

I have found OS X's restore app/window process to be less than lackluster and I need to guarantee certain apps start first before others (such as ScreenRecycler as I need applications to open on the other display when they fire up).

  • FYI, so far, and I am not happy with this solution, but I sprang and bought a program that handles this for me. I won't mention the name so far until I potentially get some input here or anyone wants a recommendation as I don't want to be seen as running an ad. So far it works well, but I would prefer a solution that matches my initial request and can modify the launch services properly without having to rely on a crutch of an application that sits in the startup and just gates app startup (although I must say the time delays and dependency additions of this little dohicky are slick). – ylluminate Feb 27 '14 at 1:45
  • We only ask that people disclose any relationship with a program they recommend (and that it not be the only reason you participate on the site). Honest recommendations are fine as long as they are on-topic and don't read like a late night informercial. – bmike Feb 27 '14 at 23:21
3

So since I've not seen any recommendations I'm going to go ahead and put forth the answer that I've gone forward with so far.

The solution so far for me has been Startupizer. It's not optimal obviously since it is both a paid for solution and it is not a method that is directly available from the OS, but it works and has allowed me to create dependency conditions and various other delays to the order that has been helpful and met my needs.

Hope this helps someone and I certainly hope someone recommends a more OS integral solution soon.

  • There isn't likely to be any ordering from Apple. They prefer launchd and let the system decide what order / how fast to launch items as part of the design of that subsystem. Things won't necessarily start in the same order every boot as well. – bmike Feb 27 '14 at 23:20
3

If you're using a shell script to open applications, try something like this:

osascript -e 'launch app "ScreenRecycler"'
pgrep -qx Alfred||open -jga Alfred
sleep 10
pgrep -qx Mail||open -jga Mail
pgrep -qx Transmission||open -jga Transmission

You can run the script at login by for example saving the plist below as ~/Library/LaunchAgents/some.label.plist.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>some.label</string>
  <key>ProgramArguments</key>
  <array>
    <string>bash</string>
    <string>-c</string>
    <string>osascript -e 'launch app "ScreenRecycler"'
pgrep -qx Alfred||open -jga Alfred
sleep 10
pgrep -qx Mail||open -jga Mail
pgrep -qx Transmission||open -jga Transmission</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

osascript -e 'launch app "AppName" and osascript -e 'activate app "AppName" are blocked until the application finishes opening. launch doesn't make an application frontmost but activate does. If an application like TextEdit or Mail is not running, launch and activate open a new visible default window. osascript -e 'tell app "TextEdit"' -e reopen -e activate -e end also reopens a default window if TextEdit is running but has no open windows.

open -jg usually opens an application hidden (-j) and without making it frontmost (-g). For some applications like TextEdit and Mail, it opens a new visible window if the application is running but has no open windows. To avoid that, check if the application is already running with for example pgrep. The -j option for open was added in 10.8 and it is only shown in the help message and not on the man page.

lsappinfo launch launchandhide=true nofront=true /Applications/TextEdit.app also always opens TextEdit hidden and without making it frontmost. lsappinfo was added in 10.9. I don't know how to use lsappinfo to wait until an application finishes opening.

The settings for login items are stored in ~/Library/Preferences/com.apple.loginitems.plist. You can add a login item with AppleScript:

osascript -e 'tell application "System Events" to make new login item at end with properties {path:"/Applications/TextEdit.app", name:"TextEdit", hidden:true}'

Some applications and processes are started up via property lists in ~/Library/LaunchAgents/, /Library/LaunchAgents/, or /Library/LaunchDaemons/. _com.apple.SMLoginItemBookmarks in /var/db/launchd.db/com.apple.launchd.peruser.$UID/overrides.plist is used to configure login items for helper applications used by sandboxed applications like ScreenFlow, DayOne, and TuneUp.

Since 10.7 there has been a relatively long delay before some login items or launchd jobs are started. I don't know any way to reduce it, but KeyRemap4MacBook's FAQ says it is caused by Resume:

KeyRemap4MacBook does not work after boot on OS X 10.7. What should I do?

"Resume" feature introduced by Lion delays launching apps at login.

Until KeyRemap4MacBook.app is launched at login, the keyboard layout is not changed. Please wait a minute until menu of KeyRemap4MacBook is shown.

  • This is by far the easiest way to sequence starting programs rather than throwing them all in the startup preference or letting the OS auto-restore them. I should dig up a link on how to prevent auto-open and then this could be a great template for anyone not liking launchd's dependency decisions and loading algorithm. – bmike Feb 28 '14 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .