我正在尝试保存我在Safari中以PDF格式打开的网址的网页内容。我能够通过Automator成功实现它,但我希望AppleScript能够做到这一点。
这是我试图运行的脚本,这给我一个错误:
error "System Events got an error: Can’t set window \"Save\" to \"~/Desktop/Reports/\"." number -10006 from window "Save"
我做的步骤:
运行以下脚本:
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
答案 0 :(得分:1)
键盘快捷键适用于最前端的应用程序,但对于UI元素(窗口,文本字段,...),您必须指定过程
tell application "System Events"
tell application process "Safari"
keystroke "p" using {command down} -- activate print menu item
-- other lines
--
end tell
end tell