How to Run an AppleScript After Inactivity

Power Manager can run an AppleScript after a period of inactivity on Mac OS X. Unlike most other scheduling tools, Power Manager can run your AppleScript as the front most user. This means your AppleScript can interact with applications and the user; with Power Manager your AppleScript is not restricted as it is with other tools.

Power Manager can run an AppleScript after a period of inactivity on Mac OS X.

Unlike most other scheduling tools, Power Manager can run your AppleScript as the front most user. This means your AppleScript can interact with applications and the user; with Power Manager your AppleScript is not restricted as it is with other tools.

There are a few ways to create a Power Manager event to run an AppleScript after inactivity. Let’s walk through how to create an event with an inline AppleScript.

By inlining the AppleScript within the event, the event becomes self-contained. No external files or AppleScripts need to be managed or maintained.You can export this kind of event and e-mail to your colleagues as a single file. This is particularly useful for simplifying the distribution of an event across large numbers of Macs.

Create an AppleScript After Inactivity Event

  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.

  3. Choose the template Run a script after inactivity.

    Select the Run a script after inactivity Power Manager task.

  4. Click Continue to the Script step.

  5. Copy and paste in the following AppleScript into Script to run.

    #!/usr/bin/osascript
    
    say "You have been idle for 15 minutes."
    

    Copy and paste your AppleScript into Script to run.

    Notice the inclusion of the special hash-bang line: #!/usr/bin/osascript.

    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, python, php, or shell script.

  6. Continue through the remaining steps until your event is created.

    Continue passed the After Inactivity step.

    Continue passed the Time Constraints step.

    Continue passed the Inactivity Constraints step.

    The Why step provides an opportunity to document the event.

    Confirm the event should be created.

Your new Power Manager is created and ready.

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

Trigger the event via the menu bar or your iPhone.