AppleScript:Lightroom 5:action" AXShowMenu"在Smart Collection面板中不显示上下文菜单

时间:2014-10-07 11:38:59

标签: applescript lightroom

我们正在使用Applescript使用Lightroom 5(最新版本的CC)开发一个简单的自动化工具。

对于某些操作,我们需要Smart Collections面板中的上下文菜单,例如导入Smart Collection描述。

根据stackoverflow和其他地方的文档和各种来源,AXShowMenu应该显示该菜单。

到目前为止,我还无法弹出上下文菜单。

使用UIElementInspector和UI Browser,我找到了附加了AXShowMenu操作的元素。基于UI Browser提供的代码,我得到了以下脚本,我从Applescript编辑器运行:

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

请注意,如果您尝试重新创建此窗口,则窗口编号以及行数可能会有所不同。此外,最后一行只是方便,与代码无关。

在AppleScript编辑器的“结果”窗口中,我有以下内容:

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"

这意味着我确实调用了这个动作。

但......没有任何反应。

高度赞赏任何见解,解决方法等。

提前致谢。

1 个答案:

答案 0 :(得分:1)

我在 Lightroom 4 上试用你的脚本,这里的结果相同。

某些应用需要真正的点击。

试试这个

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