Use AppleScript to Control Startup Apps

  Matt Cone       May 21, 2007      Tutorials Mac Developer


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 Mail.app) 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”.

    Using AppleScript on a Mac

  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”.

    Using AppleScript on a Mac

  4. Open main.scpt with Script Editor.

    Using AppleScript on a Mac

    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.

    Using AppleScript on a Mac

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

    Using AppleScript on a Mac

  7. We know Mail.app 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.

    Using AppleScript on a 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.

    Using AppleScript on a Mac

  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.)

    Using AppleScript on a Mac

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

    Using AppleScript on a Mac

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

    Using AppleScript on a Mac

    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.

    Using AppleScript on a Mac

  13. Select Accounts.

    Using AppleScript on a Mac

  14. Select the Login Items tab.

    Using AppleScript on a Mac

  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.

    Using AppleScript on a Mac

  16. Click the plus (+) button.

    Using AppleScript on a Mac

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

    Using AppleScript on a Mac

  18. Smart Start will now appear on the list.

    Using AppleScript on a Mac

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!

Subscribe to our email newsletter

Sign up and get Macinstruct's tutorials delivered to your inbox. No spam, promise!


About    Privacy Policy    Terms and Conditions

© 2023. A Matt Cone project. CC BY-NC-SA 4.0. Made with 🌶️ in New Mexico.