How to Schedule an AppleScript on Mac OS X

Power Manager can schedule AppleScripts to run regularly, as part of a schedule. The Schedule Assistant includes tasks to help create events that will run your AppleScript daily, on specific dates, or after a period of inactivity.

The best way to schedule your AppleScript, is to create an event and include the AppleScript within the event itself. This removes any need for a separate AppleScript file. Your Power Manager event can be shared with others, and moved from Mac to Mac without needing additional files.

Create a Scheduled AppleScript

  1. Launch System Preferences and select Power Manager.
  2. Click "Add…" to create a new event.
    Click Add… to create a new event in Power Manager's System Preference
  3. Choose the template "Run a script daily".
    Choose the "Run a script daily" task from Power Manager's Schedule Assistant
  4. Copy and paste your AppleScript into the "Script" step.
  5. Add the following 'hash-bang' line to the top of your script:

    The hash-bang line tells Mac OS X what program should be used to run your script. In this case, we use osascript to run your AppleScript.

    Other hash-bang lines would allow you to write scripts in other languages, such as perl, ruby, or shell script.

    Copy and paste your AppleScript in, remember to add the hash-bang
  6. Continue through the remaining steps until your event is created.
    Your AppleScript event is ready and scheduled

Your AppleScript is now scheduled and ready to run. The Schedule Assistant has created an event that will run your AppleScript in the front most user's session.

If needed, Power Manager will automatically wake up your Mac in order to perform your AppleScript. Thanks to Power Manager, you have one less reason to leave your Mac running any longer than necessary.

Trigger your AppleScript on-demand using the Power Manager status menu bar

Your event has been marked as having on-demand behaviour. Administrators on your Mac can trigger your AppleScript at any time. You can do this through the Power Manager status menu or via the command line tool pmctl.

To share your AppleScript event, click and drag the event from Power Manager onto your desktop. The resulting file can be e-mailed to friends or colleagues.

This article was posted in , , , and and tagged , , , , and .

Published by Graham Miln on