Skip to content

Instantly share code, notes, and snippets.

@ddbeck
Last active August 29, 2015 14:22
Show Gist options
  • Save ddbeck/59b9dc22c4bb13eb8a8a to your computer and use it in GitHub Desktop.
Save ddbeck/59b9dc22c4bb13eb8a8a to your computer and use it in GitHub Desktop.
A script to toggle distractions from Mac OS X Dock badges
// Use this Mac OS X automation script to quickly hide notifications for
// distracting apps. Put the names of the distracting apps in the
// `distractingApps` array and save the script. Run the script to toggle the
// badges on and off.
// Tip: To run this script much faster, move the distracting apps to the top of
// the list in System Preferences's Notifications pane.
var distractingApps = ['Tweetbot', 'Slack']
function isDistracting (appName) {
for (var i = 0; i < distractingApps.length; i++) {
if (distractingApps[i] === appName) {
return true
}
}
return false
}
function main () {
var se = Application('System Events')
var prefsApp = Application('System Preferences')
prefsApp.activate()
prefsApp.reveal(prefsApp.panes.byId('com.apple.preference.notifications'))
var prefsWindow = se.processes.byName('System Preferences').windows[0]
var apps = apps = prefsWindow.scrollAreas[0].tables[0].rows
for (var i = 0, len = apps.length; i < len; i++) {
var appName = apps[i].uiElements[0].name()
if (isDistracting(appName)) {
apps[i].selected = true
// turn off Dock badges (you could add similar lines for the other
// notification types too)
prefsWindow.groups.at(0).checkboxes.byName('Badge app icon').click()
distractingApps.splice(distractingApps.indexOf(appName), 1)
if (distractingApps.length === 0) {
break
}
}
}
prefsApp.quit()
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment