Skip to content

Instantly share code, notes, and snippets.

@rowdyrotifer
Last active December 31, 2015 07:39
Show Gist options
  • Save rowdyrotifer/f21519e4c31c35c93b70 to your computer and use it in GitHub Desktop.
Save rowdyrotifer/f21519e4c31c35c93b70 to your computer and use it in GitHub Desktop.
Fall asleep while watching videos? Want your browser tab to close after X seconds? For OS X with Chrome/Safari. Example uses: "closebrowser chrome 3600" "closebrowser safari 3000"
#!/usr/bin/env bash
if [[ $1 == "chrome" ]]
then
echo "Closing active tab of Google Chrome in $2 seconds."
sleep $2
osascript -e 'tell app "Google Chrome" to close active tab of front window'
elif [[ $1 == "safari" ]]
then
echo "Closing active tab of Safari in $2 seconds."
sleep $2
osascript -e 'tell app "Safari" to close current tab of first window'
fi
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment