How to Display a Message After a Long Task

Power Manager is frequently used to start long running tasks. While any event is running, Power Manager's menu bar changes to show a small cog. Sometimes this small indicator is not enough.

Being able to tell the user that the task has finished can be useful. Let's look at how to use AppleScript to present a dialog to the active user.

An AppleScript dialog to notify the user.

We are going to start by extending an existing event. Our event performs a back up of the Mac's hard drive to an external drive. The back up can take a few minutes and we want to to be told when it has finished.

Show a Message Using AppleScript

  1. Launch System Preferences and select Power Manager.
    Open Power Manager.
  2. Open the event to edit in the event editor; hold down the Option and double-click on your event.
    Open the Power Manager event in the event editor.
  3. Add a new action; select Add an action > Run Script > AppleScript.
    Add a new Run Script action to the Power Manager event.
  4. Edit the new action; select the Action's Action cog > Edit.
    Edit the new Power Manager Run Script action.
  5. Copy and paste the following AppleScript into the Script field:
    #!/usr/bin/osascript
    
    tell application "Finder" to display dialog "Your back up has finished."
    Copy and paste in the AppleScript into the Script field.
  6. Click Apply to save the changes to the new action.
  7. Click Save to save the changes to the event.
    Apply and Save the changes to the Power Manager event.

With your event modified, take the time to test it works as expected. Try triggering your event and waiting for the new message to appear.

Does the message appear too soon? Check to see if the action before your Run Script action has an option called Continue set to Immediately. You can change this behaviour to On Exit. This setting tells Power Manager to wait for the earlier action to finish completely, before running the next action.

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

Published by Graham Miln on