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
Launch System Preferences and select Power Manager.
Click Add… to create a new event.
Choose the template Run a script after inactivity.
Click Continue to the Script step.
Copy and paste in the following AppleScript into Script to run.
#!/usr/bin/osascript say "You have been idle for 15 minutes."
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.
Continue through the remaining steps until your event is created.
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.