Mac Automator - 合并pdfs,更改原始pdf的文件名,并将新pdf保存在名称为pdf 1的同一文件夹中

时间:2015-03-25 02:12:05

标签: macos pdf applescript osx-yosemite automator

Mac Yosemite 10.10.2。假设我有两个pdf,myPdf1.pdf和myPdf2.pdf,位于/ myFolder中。我想要一个执行以下操作的服务或脚本:

  1. 将原始pdf重命名为_MERGED_myPdf1.pdf和_MERGED_myPdf2.pdf
  2. 创建并保存新合并的pdf为/myFolder/myPdf1.pdf
  3. 我尝试了很多无法解决的问题。我从这里开始Mac Automator - Combine PDF files, save in same folder

    我的问题在于最后一步:将Finder项目移动到containerPath。我合并的pdf将转移到桌面。

1 个答案:

答案 0 :(得分:0)

我找到了一个使用AppleScript的解决方法,它可以绑定到Automator服务或应用程序中。我没有重命名输入的pdfs,而是将它们移动到文件夹中。

on run {input, parameters}
tell application "Finder"
    set trashFolder to "MacHD:path:to:some:folder"
    set outputFolder to container of (item 1 of input)
    set outputName to name of (item 1 of input)
    set outputFile to (outputFolder as text) & outputName
    repeat with p in input
        move p to trashFolder with replacing
    end repeat
    set pdfFiles to ""
    repeat with p in input
        set pdfFiles to pdfFiles & " " & quoted form of POSIX path of p
    end repeat
    --display dialog outputFile
    --display dialog pdfFiles       
    do shell script "/System/Library/Automator/Combine\\ PDF\\ Pages.action/Contents/Resources/join.py " & "-o " & quoted form of POSIX path of outputFile & pdfFiles
    return outputFile as alias
end tell

结束