Safari Applescript“另存为”

Safari Applescript“另存为”,safari,applescript,savefiledialog,reader,Safari,Applescript,Savefiledialog,Reader,我有一个AppleScript,可以打开Safari网页并将其移动到Reader视图中,然后保存为PDF 我希望它以默认文件名保存为PDF,但始终在同一特定位置。我不知道该怎么做 当前,AppleScript的运行方式为: tell application "System Events" tell application process "Safari" set frontmost to true repeat until window 1 exists end rep

我有一个AppleScript,可以打开Safari网页并将其移动到Reader视图中,然后保存为PDF

我希望它以默认文件名保存为PDF,但始终在同一特定位置。我不知道该怎么做

当前,AppleScript的运行方式为:

tell application "System Events"
tell application process "Safari"
    set frontmost to true

    repeat until window 1 exists
    end repeat

    # Render page in Safari Reader
    keystroke "r" using {command down, shift down}

    delay 0.02

    -- Print; wait until the sheet is visible   
    click menu item "Print…" of menu 1 of menu bar item "File" of menu bar 1

    repeat until sheet 1 of window 1 exists
    end repeat

    set thePopUp to first pop up button of sheet 1 of window 1 whose description is "Presets"
    click thePopUp
    click menu item "Default Settings" of menu 1 of thePopUp --replace if desired with your preferred preset

    click menu button "PDF" of sheet 1 of window 1
    click menu item "Save as PDF…" of menu 1 of menu button "PDF" of sheet 1 of window 1 -- Save as PDF...
    tell application "Finder"
        set filesavepath to "/Users/Ariel/Google Drive/To print"
    end tell
end tell
结束语

来自“告诉应用程序查找器”的AppleScript的最后一部分实际上并没有将页面保存到我想要的位置。请你帮我把这个拿出来好吗。谢谢你的帮助


Ariel

要在标准的“另存为”对话框中选择路径,您可以键入常用快捷键:

命令shift d=桌面 命令shift A=应用程序 命令shift O=文档 命令shift H=Home 命令shift G=新建对话框,询问您所在位置的路径。 例如,我想将我的_测试保存在Documents/mySafari/my_子文件夹中

tell application "Safari"
activate
tell application "System Events" to tell application process "Safari"
    keystroke "r" using {command down, shift down} -- read mode
    delay 0.5
    click menu item 17 of menu 1 of menu bar item 3 of menu bar 1 -- export as PDF (Safari 9.0.2 / El Capitain)
    delay 0.5
    keystroke "h" using {command down, shift down} -- go home directory
    keystroke "g" using {command down, shift down} -- go to dialog
    keystroke "mySafari/my_subfolder" -- path from Documents folder
    keystroke return -- close go to dialog
    keystroke "My_test" -- fill file name from save as dialog
    keystroke return -- close the save as dialog
end tell
end tell
警告:

1我使用的Safari版本9.0.2中的“另存为PDF”菜单项的数量可能会更改,那么它是17。如果您使用菜单标题,可能会更容易,但您将链接到您的系统语言!它可能和我的不一样

2文件夹路径也是本地语言:主要文件夹,如库、图片、桌面。。。翻译成当地语言。使用本地语言版本。例如,法语操作系统中的文件夹“图片”是“图像”