How to Run a Script When Your Mac Powers On

Learn how run a script when your Mac powers on or wakes up with Power Manager. This recipe can be expanded to schedule AppleScripts and Automator workflows.

Being able to run a script each time your Mac powers on is surprisingly useful. With a short script, Automator workflow, or AppleScript you can perform repetitive set-up tasks that help make sure your Mac is ready for productive work.

Power Manager lets you trigger events when your Mac wakes up or powers on.

As an example, let’s create an event that turns on and off power to the AirPort interface. This little trick can help fix numerous wireless problems.

Create a Power On Event

  1. Launch Power Manager.

  2. Create an empty event. Create an empty foundation event An empty event

  3. Open the event in the event editor. Open the event in the event editor

  4. Add a Power On trigger. Event with a power on trigger

  5. Add a Run Script > Shell Script action. Event with trigger and action

  6. Edit the Run Script step by clicking on the Cog icon.

  7. Copy and paste in your script:

    #!/bin/sh
    
    # Turn off Airport on en0
    ifconfig en0 down
    
    # Turn on Airport on en0
    ifconfig en0 up
    
  8. Change the Short User Name to root to provide the privileges needed to change your Mac’s wireless state. Run script in editable state

  9. Apply the Run Script changes.

  10. Save the event changes. Untitled AirPort reset event complete

Your new power on event is ready and will be performed when your Mac next powers on or wakes up.

Renamed power on event in Power Manager

You can change the event name either in the event editor, or directly from the list of events. To change the event name, select the event and press Enter.