How to Schedule an AppleScript Minutes After Login

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.

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.

Most events are created to occur alongside a specific trigger. These triggers are typically at predetermined times, when the user logs in or out, or when the computer wakes up.

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.

An AppleScript reminder dialog.

An AppleScript reminder dialog.

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

  1. Launch Power Manager.

  2. Click Add… to create a new event.

Click Add… to create the new event

Click Add… to create the new event

  1. Choose the Run a Script template and Continue.

Select the Run a script template.

Select the Run a script template.

  1. 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"

Copy and paste in your AppleScript.

Copy and paste in your AppleScript.

  1. Continue through the When step.

Continue through the When step.

Continue through the When step.

  1. Continue through the Constraints step.

Continue through the Constraints step.

Continue through the Constraints step.

  1. On the Why step name and provide optional notes about your new event.

Name and document your event in the Why step.

Name and document your event in the Why step.

  1. Add the event on the Confirm step.

Click Add on the Confirm step.

Click Add on the Confirm step.

The standard AppleScript event is ready to be customised.

The standard AppleScript event is ready to be customised.

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

  1. Open the event in the event editor. Hold down the Option key and double-click on the event.

Customise the event with Power Manager’s event editor.

Customise the event with Power Manager’s event editor.

  1. Delete the date based trigger. Click on the Action (cog) menu and select Delete….

Use the trigger’s Action (cog) menu to select Delete.

Use the trigger’s Action (cog) menu to select Delete.

  1. With the event pared back to the AppleScript action, add a log in trigger. Click on Add a trigger and select Log In.

The event is now pared back to the AppleScript action.

The event is now pared back to the AppleScript action.

  1. Add a delay before the AppleScript. Click Add an action and select Wait.

  2. Drag the new Wait action above the AppleScript action.

  3. Edit the Wait action to change the time to wait before continuing. Click on the Action (cog) menu of the action.

  4. Apply your changes and Save the event.

Add the log-in trigger and wait action to the event.

Add the log-in trigger and wait action to 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.

The customised event is finished and ready to test.

The customised event is finished and ready to test.

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.