1

I found this link to remove a badge icon from a single app.

Disable badge for specific app with a script

Is it possible to create a script with multiple apps to remove all badges at once?

Running High Sierra 10.13.3

  • Is it possible? Yes. What specifically would you like to do? What have you tried? – Allan Mar 8 '18 at 0:09
  • Id like to run a script to remove badge app icons from all message and email applications. Currently I have four separate scripts that take care of apps individually. – yowats0n Mar 8 '18 at 0:29
0

The following example AppleScript code was tested under macOS High Sierra.

The following is modified code from my answer you linked in your OP:

This version acts on applications in Notification Center in System Preferences that are defined in the appNameList list.

Change the application names and or add or remove them in the appNameList list as needed:

Example AppleScript code:

set appNameList to {"Calendar", "Games", "Mail", "Messages"}

if running of application "System Preferences" then
    quit application "System Preferences"
    delay 1
end if
tell application "System Preferences"
    set the current pane to pane id "com.apple.preference.notifications"
    delay 1
    tell application "System Events"
        tell table 1 of scroll area 1 of window 1 of application process "System Preferences"
            repeat with i from 2 to (count rows)
                select row i
                delay 0.25 --   # Do not set any lower, increase if necessary!
                set theValue to (value of static text 1 of group 1 of UI element 1 of row i)
                repeat with thisApp in appNameList
                    if theValue contains thisApp then
                        --  # Use 0 with clickCheckBox() to check the check box.
                        --  # Use 1 with clickCheckBox() to uncheck the check box.
                        my clickCheckBox(1)
                    end if
                end repeat
            end repeat
        end tell
    end tell
    quit
end tell

on clickCheckBox(i as integer)
    tell application "System Events"
        tell group 1 of window 1 of application process "System Preferences"
            --  # if the value of checkbox is 0, it's unchecked.
            --  # if the value of checkbox is 1, it's checked.  
            if value of checkbox "Badge app icon" is equal to i then
                click checkbox "Badge app icon"
            end if
        end tell
    end tell
end clickCheckBox

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 additional delay commands may or may not be needed. Adjust values of and or add/remove the delay commands as appropriate.



This version acts on all applications in Notification Center in System Preferences.

Example AppleScript code:

if running of application "System Preferences" then
    quit application "System Preferences"
    delay 1
end if
tell application "System Preferences"
    set the current pane to pane id "com.apple.preference.notifications"
    delay 1
    tell application "System Events"
        tell table 1 of scroll area 1 of window 1 of application process "System Preferences"
            repeat with i from 2 to (count rows)
                select row i
                delay 0.25 --   # Do not set any lower, increase if necessary!

                --  # Use 0 with clickCheckBox() to check the check box.
                --  # Use 1 with clickCheckBox() to uncheck the check box.

                my clickCheckBox(1)

            end repeat
        end tell
    end tell
    quit
end tell

on clickCheckBox(i as integer)
    tell application "System Events"
        tell group 1 of window 1 of application process "System Preferences"
            --  # if the value of checkbox is 0, it's unchecked.
            --  # if the value of checkbox is 1, it's checked.  
            if value of checkbox "Badge app icon" is equal to i then
                click checkbox "Badge app icon"
            end if
        end tell
    end tell
end clickCheckBox

For a version that acts on just one specific application in Notification Center in System Preferences, see my answer to: Disable badge for specific app with a script


Note: The example AppleScript code is just that and does not employ any other error handling then what's shown 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.

  • Awesome! To my understanding this will remove badge app icons from every app. Are there any variables I can enter to remove only 4 or 5 apps? If not this will do just fine! – yowats0n Mar 8 '18 at 0:59
  • @yowats0n, I've updated my answer to accommodate what's mentioned in your comment to my answer. – user3439894 Mar 8 '18 at 1:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .