【问题标题】:Make my applescript process specified files in the current directory?让我的applescript处理当前目录中的指定文件?
【发布时间】:2012-04-22 19:33:21
【问题描述】:

我需要定期从 word 文件生成 PDF,而且我已经厌倦了手动操作。

我所做的只是手动打开一个文件,然后单击“另存为 PDF”。因此,有人会认为 applescript 是一种非常简单的方法。 [如果您有除 applescript 之外的其他方法,我愿意接受。]

我快到了,下面的脚本可以工作,除了完整路径是硬编码的。

    tell application "Microsoft Word"
    open file "Macintosh HD:Users:me:repos:training:class:Activities:ActivityGuide.docx"
    set doc to document "ActivityGuide.docx"
    save as doc file name "Macintosh HD:Users:me:repos:training:class:Activities:ActivityGuide.pdf" file format format PDF
end tell

我需要它在其他机器上为其他人工作,因此用户名和路径的其他部分可能会改变。如果我可以从脚本的当前目录执行此操作,我会被设置。

我发现了这个:Applescript to launch file from current folder?

tell application "Finder"
    open file "somefile.txt" of folder of (file (path to me))
end tell

这适用于通过 Finder 从 Word 中的当前目录打开应用程序,但如果我要使用“另存为”,我认为我需要使用“Microsoft Word”应用程序打开它。但是如果我将“Finder”的应用程序更改为“Microsoft Word”,这种打开方法就不起作用了。

欢迎提出任何建议。 [编辑:清晰度]

【问题讨论】:

    标签: pdf ms-word applescript


    【解决方案1】:

    试试这个

    set x to path to me
    tell application "Finder" to set tFile to (file "ActivityGuide.docx" of (container of x)) as alias
    
    set newFile to (text 1 thru -5 of (tFile as string)) & "pdf"
    tell application "Microsoft Word"
        open tFile
        tell document 1
            save as file name newFile file format format PDF
            close saving no
        end tell
    end tell
    

    【讨论】:

    • 效果很好。感谢您的帮助!
    【解决方案2】:

    系统偏好设置:键盘:快捷方式:应用程序快捷方式:所有应用程序下的另一件事可能对您有所帮助

    创建一个名为“另存为 PDF...”的快捷方式,将快捷方式分配给 command+P,因为大多数应用程序是打印的快捷方式,然后只需按两次,它就会提示您将其另存为 PDF (我从 David Sparks 那里得到了这个提示)并且根据应用程序,它将默认为打开文件的位置。您也可以使用应用程序默认文件夹 X 进行设置。

    希望这更像是解决其他问题的全局解决方案,但看起来您已经有了解决这个孤立问题的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 2013-06-08
      • 1970-01-01
      • 2011-03-10
      • 2015-03-06
      相关资源
      最近更新 更多