要在AppleScript中访问Preview.app,您可以使用以下代码示例:
-- 打开Preview.app
tell application "Preview"
activate
end tell
-- 打开指定的文件
tell application "Preview"
open "/path/to/your/file.jpg"
end tell
-- 选择窗口
tell application "System Events"
tell process "Preview"
set frontmost to true
end tell
end tell
-- 获取当前显示的文档
tell application "Preview"
set currentDocument to name of front document
display dialog "当前打开的文档是:" & currentDocument
end tell
-- 关闭Preview.app
tell application "Preview"
quit
end tell
这些代码片段演示了一些常见的操作,例如打开Preview.app、打开指定的文件、选择窗口、获取当前显示的文档以及关闭Preview.app。
请注意,您可能需要在“系统偏好设置”>“安全性与隐私”>“隐私”>“辅助功能”中将AppleScript编辑器添加到允许的应用程序列表中,以便在使用AppleScript时访问其他应用程序的权限。
另外,请根据您的具体需求修改代码中的路径和文件名。