Applescripts when the Macbook Wakes Up or Sleeps

by John Ryding

I’ve been getting into Applescript development lately and found a nifty program to run some scripts whenever I put my macbook to sleep or wake it up. The program is called SleepWatcher and here are the steps you can take to get it working:

  1. Download and install SleepWatcher

  2. Create two scripts in your home directory (~/) named .sleep and .wakeup.

  3. Copy and paste the following into your .sleep script:
    #!/bin/sh
    osascript ~/Library/Scripts/sleep.scpt
    
  4. Copy and paste the following into your .wake script:
    #!/bin/sh
    osascript ~/Library/Scripts/wake.scpt
    
  5. Run “chmod +x” on .sleep and .wake

  6. Open AppleScript Editor, create a sleep.scpt and wake.scpt and save it to ~/Library/Scripts/

Alternatively, you can download the two scripts I wrote and modify them for your tasks.

My sleep script does the following:

  • Disconnect from my work VPN
  • Turn off Bluetooth

Download Sleep Script

My wake up script automates:

  • Check if there is an internet connection and determine the wireless network
  • If I am on my school’s wireless, turn off my bluetooth and connect to my work VPN
  • If I am on my home network, turn on bluetooth and mount my network drives

Download Wake Up Script