It seems that I got it and it works also when the Dock is autoHiding.
set whichApp to "Hexedit" # EDIT to fit your needs
set the_App to application id ("com.apple.dock")
set path2app to path to the_App as text
set OPTIONS_loc to localized string "OPTIONS" from table "DockMenus" in bundle (path2app as «class furl») --> "Options"
set REMOVE_FROM_DOCK_loc to localized string "REMOVE_FROM_DOCK" from table "DockMenus" in bundle (path2app as «class furl») --> "Supprimer du Dock"
-- set KEEP_IN_DOCK_loc to localized string "KEEP_IN_DOCK" from table "DockMenus" in bundle (path2app as «class furl») --> "Garder dans le Dock"
tell application "System Events" to tell process "Dock"
set frontmost to true
-- class of UI elements --> {list}
tell list 1
--class of UI elements --> {UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element, UI element}
set found to false
repeat with anUIelement in UI elements
try
tell anUIelement
set found to value of attribute "AXTitle" is whichApp
if found then exit repeat
end tell
end try
end repeat
if found then
tell anUIelement
-- name of actions --> {"AXPress", "AXShowMenu", "AXShowExpose"}
perform action "AXShowMenu"
tell menu 1
-- name of menu items --> {"iBooks", missing value,"Options", missing value, "Afficher toutes les fenêtres", "Masquer", "Masquer les autres", "Quitter", "Forcer à quitter"}
click menu item OPTIONS_loc
tell menu item OPTIONS_loc to tell menu 1
-- name of menu items --> {"Garder dans le Dock", "Ouvrir avec la session", "Afficher dans le Finder"}
--> {"Supprimer du Dock", "Ouvrir avec la session", "Afficher dans le Finder"}
set maybe to name of menu item 1
if maybe is REMOVE_FROM_DOCK_loc then
click menu item 1
else
# The first item is KEEP_IN_DOCK_loc, is it checked ?
--name of attributes of menu item 1 --> {"AXRole", "AXRoleDescription", "AXParent", "AXEnabled", "AXPosition", "AXSize", "AXTitle", "AXHelp", "AXSelected", "AXMenuItemCmdChar", "AXMenuItemCmdVirtualKey", "AXMenuItemCmdGlyph", "AXMenuItemCmdModifiers", "AXMenuItemMarkChar", "AXMenuItemPrimaryUIElement", "AXFrame"}
if value of attribute "AXEnabled" of menu item 1 is true then click menu item 1
end if
end tell # menu item.
end tell # menu 1
end tell # anUIelement
end if
end tell # list 1
end tell
edit #1 : I added a couple try . end try because here, one UI element has no title and trying to get it issue an error.
edit #2 : no longer use an index when looping upon UI elements.
Yvan KOENIG running El Capitan 10.11.2 in French (VALLAURIS, France) mercredi 13 janvier 2016 18:48:23