Skip to content

Instantly share code, notes, and snippets.

@chew-z
Last active November 13, 2016 06:05
Show Gist options
  • Save chew-z/767980ba0aef9258bdcd to your computer and use it in GitHub Desktop.
Save chew-z/767980ba0aef9258bdcd to your computer and use it in GitHub Desktop.
sleep script for sleepwatcher (OSX)
#!/bin/bash
echo "I feel like napping right now..."
echo $(date +"%c")
ADAPTER=$(networksetup -listallhardwareports | grep -A1 Wi-Fi | awk '/Device:/ {print $2}')
CONN=$(networksetup -getairportnetwork "$ADAPTER")
echo "$CONN"
# switch OFF WiFi first
networksetup -setairportpower "$ADAPTER" off
# switch off proxies = switch off internet for most apps
/usr/local/bin/brew services stop polipo
/usr/local/bin/brew services stop privoxy
# remove mutt's tmp files (half-written emails, attachments, etc.)
rm -f /tmp/mutt-maX*
rm -f /tmp/mutt-attach/*
# close sensitive applications
osascript <<EOD
tell application "KeepassX" to quit
tell application "Calendar" to quit
tell application "Remote Desktop Connection" to quit
tell application "Safari" to quit
tell application "Sublime Text" to quit
# tell application "Mail" to quit
# tell application "Chromium" to quit
# tell application "Firefox" to quit
# tell application "MacVim" to quit
# tell application "Markoff" to quit
# tell application "Tweetbot" to quit
EOD
echo "Done. Now it's time to sleep."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment