1

Screenshot

For my application MuteSpotifyAds I wan't to add a feature that automatically enables the Private Session mode.

To do so, I wan't to toggle the menu bar item Private Session in the menu Spotify of the OSX menu bar. I use the following applescript, which works:

Source: https://stackoverflow.com/a/16497564/6286431

tell application "System Events" to tell process "Spotify" tell menu bar item 2 of menu bar 0 click click menu item "Private Session" of menu 1 end tell end tell

The problem is that I have to check if the checkbox is already ticked, because else I would disable the Private Session.

Is there a way to check if the menu checkbox is already ticked?

I've already tried this, but seems to only work for checkboxes in actual windows.

If you have a solution that does not use applescript, that's also good!

Simon Meusel
  • 200
  • 3
  • 16

1 Answers1

2

The information if the menu item is checked is in the attribute "AXMenuItemMarkChar" of the menu item

tell application "System Events" to tell process "Spotify"
    tell menu bar item 2 of menu bar 1 -- AppleScript indexes are 1-based
        tell menu item "Private Session" of menu 1
            set isChecked to value of attribute "AXMenuItemMarkChar" is "✓"
            if not isChecked then click it
        end tell
    end tell
end tell
vadian
  • 274,689
  • 30
  • 353
  • 361