我正在尝试将我在 Safari 中打开的 URL 的 Web 内容保存为 PDF。我能够通过 Automator 成功实现它,但我想要一个 AppleScript 来做到这一点。
这是我试图运行的脚本,它给我一个错误:
error "System Events got an error: Can’t set window \"Save\" to \"~/Desktop/Reports/\"." number -10006 from window "Save"
我做的步骤:
- 为另存为 PDF 创建了快捷方式...
- 打开有一些网页内容的 Safari
运行以下脚本:
set destination_folder to "/Users/swatt/Desktop/Reports" tell application "System Events" keystroke "p" using {command down} -- activate print menu item delay myDelay keystroke "p" using {command down, option down, control down} -- to select the Save as PDF… option keystroke "g" using {shift down, command down} -- to select the folder location set value of text field 1 of sheet of window "Save" to destination_folder -- Now click the Go button click button "Go" of sheet of window "Save" delay myDelay -- Now that we are in our desired folder, set the file name and save set value of text field 1 of window "Save" to "TestResults.pdf" --click button "Save" of window "Save" click button "Go" end tell