Skip to content

Instantly share code, notes, and snippets.

@peterhurford
Last active June 25, 2022 08:03
Show Gist options
  • Save peterhurford/50e9029ea43e7f4cbb8ca3884c75d45b to your computer and use it in GitHub Desktop.
Save peterhurford/50e9029ea43e7f4cbb8ca3884c75d45b to your computer and use it in GitHub Desktop.
## 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"
activate
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