问题
We are developing a simple automatization tool using Lightroom 5 (the newest version of the CC) using Applescript.
For some actions, we need the context menu in the Smart Collections panel, for example to import Smart Collection descriptions.
According to the documentation and various sources here on stackoverflow and elsewhere, AXShowMenu should bring up that menu.
So far, I have not been able to make that context menu pop up.
Using UIElementInspector and UI Browser, I located the element which does have the AXShowMenu action attached. Based on the code provided by UI Browser, I got the following script, which I run from the Applescript Editor:
tell application "Adobe Photoshop Lightroom 5"
activate
tell application "System Events"
tell process "Lightroom"
set frontmost to true
perform action 1 of static text "Smart Collections" of group 1 of row 11 of outline 1 of scroll area 1 of window 6
delay 2
end tell
end tell
end tell
tell application "AppleScript Editor" to activate
Note that if you try to recreate this, the number of the window as well as the number of the row may be different. Also, the last line is just convenience, and not really relevant for the code.
In the Results window in AppleScript Editor, I have the following:
perform action 1 of static text "Smart Collections" of group 1 of row 11 of outline 1 of scroll area 1 of window 6 of process "Lightroom"
--> action "AXShowMenu" of static text "Smart Collections" of group 1 of row 11 of outline 1 of scroll area 1 of window 6 of application process "Adobe Photoshop Lightroom 5"
which means that I did invoke the action.
But … nothing happens.
Any insight, workaround etc. is highly appreciated.
Thanks in advance.
回答1:
I try your script on Lightroom 4, same results here.
Some application need a real click.
Try this
tell application "System Events"
tell process "Lightroom"
set frontmost to true
set {x, y} to position of text field 1 of row 11 of outline 1 of scroll area 1 of window 6
my realClick(x, y, "Right") -- "Right" = mouseRight, "Left" = mouseLeft
delay 0.5
key code 125 -- arrow down to select first menuitem
keystroke return -- to click on menuitem
end tell
end tell
on realClick(x, y, leftRight)
do shell script "/usr/bin/python -c 'import Quartz.CoreGraphics as qcg
def mouseEvent(type):
e=qcg.CGEventCreateMouseEvent(None, type, (" & x & "," & y & "), r)
qcg.CGEventPost(qcg.kCGHIDEventTap, e)
if \"" & leftRight & "\" is \"Left\": r= qcg.kCGMouseButtonLeft; mouseEvent(qcg.kCGEventLeftMouseDown); mouseEvent(qcg.kCGEventLeftMouseUp)
else: r= qcg.kCGMouseButtonRight; mouseEvent(qcg.kCGEventRightMouseDown); mouseEvent(qcg.kCGEventRightMouseUp)'"
end realClick
来源:https://stackoverflow.com/questions/26235153/applescript-lightroom-5-action-axshowmenu-in-smart-collection-panel-does-not