【问题标题】:Applescript 'Save as'Applescript'另存为'
【发布时间】:2016-01-21 20:58:45
【问题描述】:

我有一个 AppleScript 可以打开将 Safari 网页移动到阅读器视图,然后另存为 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 的最后部分,来自“告诉应用程序查找器”,实际上并没有使页面保存在我想要的位置。请你帮我解决这个问题。感谢您的帮助。

爱丽儿

【问题讨论】:

    标签: safari applescript savefiledialog reader


    【解决方案1】:

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

    • command shift d = 桌面
    • 命令转换 A = 应用程序
    • command shift O = 文档
    • command shift H = Home
    • command shift G = 新对话框,询问您所在位置的路径。

    例如,我想将“my_Test”保存在文件夹 Documents/mySafari/my_subfolder 中

    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) “另存为 PDF”菜单项的数量可能会在您的 Safari 版本上发生变化(我使用的是 9.0.2,然后是 17)。如果你使用菜单标题可能会更容易,但是你链接到你的系统语言!(它可能与我的不同)

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

    【讨论】:

      猜你喜欢
      • 2015-11-17
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      • 2016-07-16
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多