Created
October 15, 2015 05:04
-
-
Save benkuhn/6e975d297a432d1747a9 to your computer and use it in GitHub Desktop.
Pop up a notification prompting you to close Slack if it's open
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "Notifications Scripting" | |
# set show event handler results to true | |
set event handlers script path to (path to me) | |
display notification "Slack is running" message "Are you waiting on an @mention?" action button "No" other button "Yes" | |
end tell | |
end if | |
using terms from application "Notifications Scripting" | |
on notification activated activation type 2 # action button | |
tell application "Slack" to quit | |
end notification activated | |
end using terms from |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I couldn't figure out how to display a system notification with custom buttons that tell you which button was clicked. Instead I used Finder to display the notification—a little bit hacky, but it works.
I put this in
~/bin/slack_watcher.applescript
:Then I added this to the crontab (
crontab -e
) to have the script run every 5 minutes: