user429620
user429620

Reputation:

Accesing third party menu extras (menulets) via applescript?

Is it possible to access third party menulets via applescript? (Those icons displayed in the top right corner of the global menu bar).

I basically want to know if a certain menu item (that is shown when you click the icon) is enabled or disabled (greyed out).

Any resources on this?

Thanks

Upvotes: 0

Views: 1513

Answers (1)

regulus6633
regulus6633

Reputation: 19030

Yes, menu items have an "enabled" property. That property is false for "greyed out" menu items. So for example, I show the clock menulet in my main menu bar. If I wanted to know the enabled property of each of its menu items I could do this...

tell application "SystemUIServer" to activate

set theProps to {}
tell application "System Events"
    tell process "SystemUIServer"
        set menulets to menu bar items of menu bar 1
        repeat with aMenu in menulets
            if (description of aMenu) is "clock" then
                click aMenu -- we have to open it to access the menu items inside it
                delay 0.2
                set clockMenuItems to menu items of menu 1 of aMenu
                repeat with aMenuItem in clockMenuItems
                    set end of theProps to {title of aMenuItem, enabled of aMenuItem}
                end repeat
            end if
        end repeat
    end tell
end tell

return theProps

Note that some of those menulets are not regular menulets. Those you have to treat differently but the concept is the same. You click the menulet then access its menu items and check their enable property.

Upvotes: 2

Related Questions