Sunday, September 8, 2013
Applescript Login Items Handler
If you're like me and like your login items in the menu bar to be in a certain order, you may find it frustrating that you have little control over the order that your system uses to launch the apps. Using System Preferences, you can somewhat control the order of Login Items under Users and Groups. What I have found though, is the order of the icons appearing may be different than the order set if some apps take longer to load than expected. To get around this, you can use a commercial app like Startupizer 2, which is a great product with many useful features. The problem I found with this, and similar apps, is that they don't control the order of icons the system installs. I run an app called BackBlaze to backup my computer to the cloud. I like to see the icon in the menubar. The app is run as a service, and so I have no control over when the icon appears. Until now.
I did a bit of Google research and found a number of AppleScripts to launch apps. I also found a snippet to determine if an app is running, and a snippet to load and unload apps. Putting it all together, I created my own script to launch my startup items. I expanded it a bit further than just the menu bar to include apps I like to have open all the time, or at least to start.
I now get the order I want.
Here is the script I created.
The first app I want to launch after the system icons are set, is Degrees, a simple weather app. The issue is with the next item. BackBlaze always sets its icon after the system icons as it is controlled by the service. I needed a way to determine if the icon was showing, and if it was, to "unload" it and reload it at the right spot. This is done with the isRunning function. Works perfectly. I unload the BackBlaze menu, which usually comes up before the Degress icon, and load it now after the Degrees icon.
Then I load Insync for Google Drive, then Dropbox and finally Wallpaper Wizard. Add a bit of delay between each app to ensure it is launched before the next one starts. Dropbox takes a bit of time to actually launch and without the delay, other icons may show up before it does.
After the menu bar is finished loading, I load a few other apps I like to have always running. To keep some of the apps from actually opening a window, I use the run command to open the app in the Dock, but hide the window.
Save the script as an application bundle and run it like an app. Most of the apps I want to control in the menu bar have a Preference setting to Launch at startup. Disable this in each app, or else it may load before your script runs. Now add your script to the Login Items under Users and Groups Preferences.
Now my desktop opens just as I want every time I restart my computer. And you can too.
To make the script not show in the dock when it runs, you can patch the app by following the directions I found in this blog, Disable the Dock Icon for Any Application. Using this method can cause some issues with some apps resulting in "code breaking" errors. Seems to work fine for this script though.
You can download my script here if you want and save yourself some time and trouble. Just edit it in AppleScript as needed and resave it.
| Share More...