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

发布于 2024-08-24 00:25:56 字数 182 浏览 2 评论 0原文

我已经尝试过这个,但它不起作用:

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

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

I have tried this but it doesn't work:

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

I have verified that my Preview is scriptable (NSAppleScriptEnabled).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你又不是我 2024-08-31 00:25:56

我做了一些研究,发现了

 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 上找到的

I did a little research and found this

 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 & "\");'"

which i found on macscripter

蓝天 2024-08-31 00:25:56

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

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

通常人们使用 GUI 脚本与 Preview 交互,或者他们找到其他方式。

On my 10.6 system Preview doesn't have an Applescript dictionary. This is something that scriptable applications need. While Preview SAYS it can do Applescript, it really can't.

It has no way to translate the "path of document 1 of window 1" into anything meaningful.

Usually people use GUI Scripting to interact with Preview, or they find another way.

悲喜皆因你 2024-08-31 00:25:56

最简单的方法是:

tell application "Preview" to return path of front document

或者,适合您的示例:

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

Simplest way is:

tell application "Preview" to return path of front document

Or, to fit your example:

tell application "Preview" to set myfile to path of front document
累赘 2024-08-31 00:25:56

即使预览处于全屏模式,要准确获取当前文档的路径,请使用:

tell application "Preview" to return path of document of front window

To get the path to the current document accurately even if Preview is in full screen mode, use:

tell application "Preview" to return path of document of front window
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文