I know that I can turn on/off the badge from the notifcation center, but is there a way to do it with a script?
If possible I would love to do for a specific app, otherwise it will be fun to turn it off for all the apps.
So far I was able to do this:
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.notifications"
tell application "System Events"
tell process "System Preferences"
select row 2 of table 1 of scroll area 1 of window "Notifications"
click checkbox "Badge app icon" of group 1 of window "Notifications"
end tell
end tell
end tell
It has only one problem:
- the list must stay the same and you have to know the Index. Is there a way to access by name?
PS: i've used the very handy http://pfiddlesoft.com/uibrowser/index-downloads.html for finding out how to identify objects
Best Answer
The following example AppleScript code works for me under macOS High Sierra:
Note: Change
"Calendar"
inset appName to "Calendar"
to the appropriate target app.System Preferences does not need to be visible for this to work and why there is no
activate
command in the example AppleScript code. Additionally if System Preferences is already open, it is first closed before the rest of the code is processed. This is done for a couple of reasons, the first of which was already stated and secondly seeing the UI Events processed is a visual distraction and can be annoying.Also note that the value of the
delay
commands may need to be adjusted for your system, and or additionaldelay
commands may or may not be needed. Adjust values of and or add/remove thedelay
commands as appropriate.For a version that acts on multiple applications and or all applications in Notification Center in System Preferences, see my answer to: Remove multiple app badge icons with one script?
Note: The example AppleScript code is just that and does not employ any error handling and is meant only to show one of many ways accomplish a task. The onus is always upon the User to add/use appropriate error handling as needed/wanted.