代码之家  ›  专栏  ›  技术社区  ›  Abhi

如何使用AppleScript获取预览中打开的文档的路径?

  •  4
  • Abhi  · 技术社区  · 16 年前

    tell application "Preview"
        set myfile to path of document 1 of window 1
    end tell
    

    我已经验证了我的预览是可编写脚本的(NSAppleScriptEnabled)。

    3 回复  |  直到 16 年前
        1
  •  8
  •   mcgrailm    13 年前

     tell application "System Events"
        tell process "Preview"
            set thefile to value of attribute "AXDocument" of window 1
        end tell
     end tell
    
    -- macos comes with php installed you can decode this file name using php
    return do shell script "php -r 'echo urldecode(\"" & thefile & "\");'"
    

    我在上面找到的 macscripter

        2
  •  2
  •   RyanWilcox    16 年前

    在我的10.6系统预览版上没有Applescript字典。这是可编写脚本的应用程序所需要的。虽然Preview说它可以做Applescript,但它真的不能。

    它无法将“窗口1的文档1的路径”转换为任何有意义的内容。

    通常人们使用GUI脚本与Preview进行交互,或者他们找到了另一种方法。

        3
  •  0
  •   user137369    7 年前

    最简单的方法是:

    tell application "Preview" to return path of front document
    

    或者,举个例子:

    tell application "Preview" to set myfile to path of front document