Skip to content

Instantly share code, notes, and snippets.

Last active June 25, 2022 08:03
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
## Slack watcher - makes sure you only have Slack running if you should to avoid being distracted
## by Patrick Brinich-Langois, Ben Kuhn, and Peter Wildeford
## To install: (1) save this script as `~/bin/slack_watcher.applescript`.
## (2) Use `crontab -e` and add `*/22 * * * * osascript $HOME/bin/slack_watcher.applescript` to your crontab
## (this will run every 22 minutes while Slack is open - Slack will be closed if you press `No`)
tell application "System Events"
set activeApp to name of first process whose frontmost is true
end tell
if application "Slack" is running and activeApp is not equal to "Slack" then
tell application "Finder"
display alert "Slack is running" message "Should you really be having Slack open right now?" buttons ["No", "Yes"] default button 1
end tell
using terms from application "AppleScript Utility"
if button returned of result = "No" then
tell application "Slack" to quit
end if
end using terms from
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment