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:
- Download and install SleepWatcher
- Create two scripts in your home directory (~/) named .sleep and .wakeup.
- Copy and paste the following into your .sleep script:
#!/bin/sh osascript ~/Library/Scripts/sleep.scpt
- Copy and paste the following into your .wake script:
#!/bin/sh osascript ~/Library/Scripts/wake.scpt
- Run “chmod +x” on .sleep and .wake
- 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
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