Post

Replies

Boosts

Views

Activity

MenuItem scripting
Hi Everyone, I'm new to mac's and AppleScript so I apologise in advance for the level of questioning/quality of code. I've been trying to create an applescript to go through every menuitem and list out the keyboard shortcuts. I've created a script to add keyboard shortcuts, but have only done so as global shortcuts. Some of them don't work in different apps so I'm trying to create a verbose list that has every menuitem for every application so I can populate my script, then eventually have application specific shortcuts for every menuitem that has a shortcut currently. Below I'm trying to generate that list of current shortcuts but I'm stuck on the syntax of getting the properties of attributes of items and displaying them. The below is where I have got to: set allMenus to {} set everything to {} set onlyEnabled to {} tell application "System Events" to tell process appName set allMenus to name of every menu of menu bar 1 end tell global testCounter global currentCounter set testCounter to 14 set currentCounter to 0 repeat with menuName in allMenus set the end of everything to strings of getAppMenuItems(appName, menuName, onlyEnabled) if currentCounter > testCounter then log "EXIT REPEAT!!!!!!!!!!!!!!!" exit repeat end if end repeat on getAppMenuItems(appProcess, appMenus, enabledItems) tell application "System Events" to tell process appProcess # Get all menu items set theItems to every menu item of menu appMenus of menu bar 1 log "BREAKAKKKKKKBREAKKKKKK" set appMenuName to name of menu appMenus of menu bar 1 --log appname repeat with theMenuItem in theItems set currentCounter to currentCounter + 1 if currentCounter > testCounter then exit repeat end if set itemAttrib to get every attribute of theMenuItem repeat with aAttrib in itemAttrib if the name of the aAttrib is "AXMenuItemCmdChar" then set props to get properties of attribute "AXMenuItemCmdChar" of every menu item of menu appMenus of menu bar 1 repeat with aProps in props if the value of aProps as text is not "missing value" then log (appMenuName & "->" & name of theMenuItem as text & "->" & value of aProps as text) end if end repeat log (appMenuName & "->" & name of theMenuItem as text & "BREAKAKKKKKKBREAKKKKKK") end if end repeat end repeat return name of every menu item of menu appMenus of menu bar 1 end tell end getAppMenuItems (* tell application "System Events" get name of menu item 2 of menu 3 of menu bar 1 of process "Finder" --> "New Folder" get every attribute of menu item 2 of menu 3 of menu bar 1 of process "Finder" --> {attribute "AXRole" of menu item "New Finder Window" of menu "File" of menu bar item "File" of menu bar 1 of application process "Finder", [...] get properties of attribute "AXMenuItemCmdChar" of [...] --> {value:"N", class:attribute, settable:false, name:"AXMenuItemCmdChar"} get properties of attribute "AXMenuItemCmdModifiers" of [...] --> {value:1, class:attribute, settable:false, name:"AXMenuItemCmdModifiers"} *) Currently this outputs: Apple->About This Mac->Q Apple->About This Mac->Q Apple->About This MacBREAKAKKKKKKBREAKKKKKK Apple->System Information…->Q Apple->System Information…->Q Apple->System Information…->Q From the output I have surmised that when I'm logging the output (log (appMenuName & "->" & name of theMenuItem as text & "->" & value of aProps as text) The properties aren't actually the properties of theMenuItem attribute, but that it has found 3 AXMenuItemCmdChar in the full Apple menu, and is just putting those 3 against each theMenuItem. I've tried a few ways around this, mainly changing set props to get properties of attribute AXMenuItemCmdChar of every menu item of menu appMenus of menu bar 1 to set props to get properties of itemAttrib or set props to get properties of attribute "AXMenuItemCmdChar" of itemAttrib but can't seem to find the right way of getting it to work. Furthermore, how I would correctly reference the parent within my log() statement (I can see the syntax for referencing the child (e.g. x of y of z) but how do you go the other way? Thanks in advance
3
0
2.1k
Jun ’23