The place to learn about your Mac. Tips and tutorials for novices and experts.

Use AppleScript to Control Startup Apps

You probably know that your Mac can automatically open applications when you turn it on or log into a user account. The problem is that automatically opening Internet-dependent applications (such as iChat or can slow down your Mac if you're not connected to the Internet.

To improve your Mac's startup time, we'll utilize a simple AppleScript to determine whether or not your Mac is connected to the Internet, and then automatically open selected applications if an Internet connection is present. If your Mac isn't connected to the Internet, the AppleScript won't launch the applications.

Here's how to do it:

  1. Start by downloading this small application. We call it Smart Start. It's the home-grown AppleScript we'll be using to implement this crazy idea.

  2. Once it has finished downloading, right click on Smart Start and select "Show Package Contents".

  3. Navigate into the application by double-clicking the contents folder, and then resources, and then finally scripts. Here you will find a document titled "main.scpt".

  4. Open main.scpt with Script Editor.

    Don't sweat it if the sight of an AppleScript gives you the willies. Our work here will be brief and simple. To better understand what this script is doing, we'll break it down into two parts.

  5. The first part of the script attempts to verify a connection to the Internet. It does this by trying to ping Google's server. Essentially, your Mac sends a small packet of data to Google's server and then listens for it to echo back. If it doesn't return, then your Mac assumes there is no Internet connection. Smart Start will then quit without opening any applications.

  6. If an Internet connection is verified, the second part of the script tells to open.

  7. We know is not necessarily one of the applications you'll want to open - we simply used it as an example. You can open any application you like. Just replace "Mail" with the name of an application installed on your Mac.

  8. You can also add as many applications as you like by simply copying and pasting the "tell application" line. Double check that you type in the application names correctly. If spell them incorrectly, your Mac won't be able to find the application, and the script will fail.

  9. As you enter text into Script Editor, you may notice that it appears purple, unlike the text around it. This is normal. Once you are finished editing the document, click "Compile". (It's the hammer icon.)

  10. Script Editor will automatically format and colorize the text appropriately.

  11. Once it's compiled, you can save the script and exit Script Editor.

    At this point, we suggest moving the Smart Start application to a safe spot on your hard drive. We chose the Applications folder.

  12. Now that you've configured your script to open applications, you need to tell your Mac to run the script when it turns on. From the Apple menu, select System Preferences.

  13. Select Accounts.

  14. Select the Login Items tab.

  15. Here, you'll find a list of applications that are set to automatically open when you log in. Any applications you chose to include in the Smart Start script must be removed from this list. Do this by selecting the application and clicking the minus (-) button.

  16. Click the plus (+) button.

  17. Locate the Smart Start application on your hard drive, and then click Add.

  18. Smart Start will now appear on the list.

That's it, you're done! The next time you log in, you can give yourself a pat on the back. Your Mac is taking a smarter approach to logging in!


Copyright © 2016 Macinstruct. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.