告诉预览获取其文档名称为" book.pdf"

时间:2017-03-20 06:07:33

标签: applescript

我试图获取其文档名称为#34; book.pdf"的窗口。这是我的方法

tell application "Preview"
    set w to every window whose document is named "book.pdf"
end

这不起作用。我尝试了大约100个排列,但我没有到达任何地方。有什么提示吗?

1 个答案:

答案 0 :(得分:0)

您可以将AXTitlecontains结合使用,并告诉System Events而不是Preview

注意我将它包装在try块中,因为如果找不到字符串匹配,myWindow将是未定义的。

set n to "book.pdf" -- whatever substring you want to find

tell application "System Events" to tell process "Preview"
    try
        set myWindow to (1st window whose value of attribute "AXMain" is true and value of attribute "AXTitle" contains n)
        log myWindow
    on error
        log "not found"
    end try
end tell