Applescript:打开预览"导出为pdf"错误:预览出错:无法获得击键" "

时间:2018-05-16 00:28:44

标签: applescript

我想打开包含预览的文件夹中的所有pdf,并使用"导出到PDF"将其导出到另一个文件夹。

到目前为止,这是我的问题。

错误

  

预览出错:无法获得击键"   "

Apple脚本

tell application "Finder"
    set fl to files of folder POSIX file "/Users/documents/PDFs" as alias list
end tell
repeat with f in fl
    tell application "Preview"
        open f
        tell application "System Events" to tell process "Preview"
            delay 0.2
            click menu item "Export as PDF…" of menu 1 of menu bar item "File" of menu bar 1
        end tell
        keystroke return
    end tell
end repeat

1 个答案:

答案 0 :(得分:0)

您收到该错误是因为keystroke return是一个系统事件命令,您可以在"预告告诉块"

中找到它

看起来keystroke return的意图是实际点击"保存"按钮,那么这对你有用......

tell application "Preview"
    activate
    tell application "System Events" to tell process "Preview"
        delay 0.2
        click menu item "Export as PDF…" of menu 1 of menu bar item "File" of menu bar 1
        delay 0.2
        click button "Save" of sheet 1 of window 1
    end tell
end tell