Applescript - 用作Droplet时不会起作用

时间:2016-03-15 09:57:11

标签: applescript automator

我试图创建一个脚本用作我在其上放置文件的Droplet,automator在Adobe Acrobat中打开它,然后AppleScript在Acrobat中运行一个操作,将其保存为优化的PDF文件特定文件夹,然后在预览中打开该新文件,并使用石英过滤器来减小PDF的大小。

如果我已经在Acrobat中打开了一个文件并且只运行该脚本,它会在Acrobat中执行操作,保存文件,然后打开预览(没有进一步了解)。但是,如果我将文件放到Droplet上,它只会给我一个错误信息。

以下是代码:

on run {input, parameters}
    tell application "System Events"
        tell application process "Acrobat"
            tell application "Adobe Acrobat Pro" to activate
            -- runs the custom action in Acrobat
            click the menu item "SAVE in 0-SEND" of menu 1 of menu item "Action Wizard" of the menu "File" of menu bar 1
        end tell
    end tell

    tell application "System Events"
        keystroke return
        -- clears the action finished message
    end tell

    tell application "Adobe Acrobat Pro"
        activate
        close documents saving no
        quit
    end tell

    -- this doesn't work yet
    tell application "Finder"
        tell application "Preview"
            open input
        end tell
    end tell
end run

1 个答案:

答案 0 :(得分:0)

我会沿着这些方向推荐一些东西......

on run
    set aFile to choose file with prompt "Please select the file to process"
    processPDF(aFile)

    -- cleanup, quit the application
    tell application "Adobe Acrobat Pro" to quit
end run


on open (theFiles)
    repeat with aFile in theFiles
        processPDF(aFile)
    end repeat

    -- cleanup, quit the application
    tell application "Adobe Acrobat Pro" to quit
end open


on processPDF(theFile)

    -- open your file
    -- do something with theFile here.
    -- close the file

end processPDF