Power Manager can schedule actions relative to a trigger. In this article we will walk through scheduling an AppleScript to run 10 minutes after logging in.
However, there is a group of problems best solved by delaying an event's actions. This class of problem benefits from delays or waiting for a sequence of triggers to pass.
Let's say you want to display a message to the user ten minutes after they have logged in. This might be to remind the user to regularly save their work, or maybe to ask them not to use the computer for too long.
We can use a small AppleScript to display the message. We can ask Power Manager to queue up the AppleScript and perform it ten minutes after each log in.
It is possible to put a loop into an AppleScript to perform the ten minute delay but Power Manager is a better solution. A looping AppleScript requires more processor time than Power Manager. The AppleScript offers no configuration or logging, and a running AppleScript can be easily interfered with by non-administrator users.
Create an AppleScript After Login Event
We are going to create a date triggered AppleScript, and then use the event editor to customise the event.
Create a Standard Event
- Launch Power Manager.
- Click Add… to create a new event.
- Choose the Run a Script template and Continue.
Copy and paste in the following AppleScript:
#!/usr/bin/osascript display dialog "Remember to save regularly!" buttons "OK" default button "OK" with icon caution giving up after 600 with title "Reminder"
- Continue through the When step.
- Continue through the Constraints step.
- On the Why step name and provide optional notes about your new event.
- Add the event on the Confirm step.
The event is now scheduled but does not yet do what we need. Using the event editor, we are going to replace the date based trigger with a log in trigger, and add a delay action before the AppleScript.
Customise the Standard Event
- Open the event in the event editor. Hold down the Option key and double-click on the event.
- Delete the date based trigger. Click on the Action (cog) menu and select Delete….
- With the event pared back to the AppleScript action, add a log in trigger. Click on Add a trigger and select Log In.
- Add a delay before the AppleScript. Click Add an action and select Wait.
- Drag the new Wait action above the AppleScript action.
- Edit the Wait action to change the time to wait before continuing. Click on the Action (cog) menu of the action.
- Apply your changes and Save the event.
The customised event is scheduled and ready to test. The event will be triggered immediately upon log in. The wait action will start at this stage. Once the waiting period is passed, the AppleScript will be performed.
You may have noticed the standard event we created provided on demand behaviour. This means you can immediately test your new event without needing to log out and back in. Use the Power Manager menu bar to manually trigger your event.