【问题标题】:Applescript to (if/then) determine file type and choose correct program to open and print file (within batch sequence)Applescript(如果/那么)确定文件类型并选择正确的程序来打开和打印文件(在批处理序列中)
【发布时间】:2014-06-27 14:07:41
【问题描述】:

在@chuck 和其他董事会帖子的大力帮助下,我收集了一个applescript,以有效地批量打印从filemaker 容器导出的文件列表到我桌面上一个名为“print”的文件夹。

我现在遇到的问题是其中一些容器导出不是 PDF(它是 Jpg、PNG、Tif 和 PDF 的混合),并且无法使用 acrobat 打开(使用 PDF 或任何其他 PDF 查看器的预览)由于各种原因,这是不可能的)...由于来自 acrobat 的错误消息必须手动关闭,脚本才能继续执行下一个文件,因此此问题有效地关闭了工作流程。

我的问题是能否命令 applescript 先确定文件类型,然后选择不同的程序来打开文档并触发打印命令并关闭窗口,然后再移动到序列中的下一个文档。

(即如果是 .pdf 则使用 acrobat 打印关闭窗口,如果不使用预览打开文件,则打印关闭窗口,重复直到打印完所有文件。)

以下是我当前的工作代码。(仅供参考)此脚本在文件生成器脚本中运行,该脚本在桌面上创建“打印”文件夹并将容器字段导出到该文件夹​​。 p>

`set myFolder to (path to desktop folder as text) & "Print:"

set myfiles to list folder myFolder without invisibles

repeat with myfile in myfiles

set mycurrentfile to ((myFolder as string) & (myfile as string)) as string
batchprint(mycurrentfile)

end repeat

on batchprint(mycurrentfile)

tell application "Adobe Acrobat Pro"
    activate -- bring up acrobat
    open alias mycurrentfile -- acrobat opens that new file    
    tell application "System Events"
        tell process "Acrobat"
            click menu item "Print..." of menu 1 of menu bar item "File" of menu bar 1
            click button "Print" of window "Print"
            tell application "System Events"
                tell process "Acrobat"
                    click menu item "Close" of menu 1 of menu bar item "File" of menu bar 1
                end tell
            end tell
        end tell
    end tell
end tell

tell application "Finder" -- to move the printed file out 
    set x to ((path to desktop folder as text) & "Printed PDFs:")
    if alias x exists then
        beep
    else
        make new folder at the desktop with properties {name:"Printed PDFs"}
    end if
    move alias mycurrentfile to folder "Printed PDFs"
end tell

结束批处理`

【问题讨论】:

    标签: pdf applescript containers batch-processing filemaker


    【解决方案1】:

    使用 Finder 测试文件类型和扩展名,然后使用 Acrobat 判断块是否为 pdf,如果不是则使用预览或其他方式。 这是它的代码结构:

    tell application "Finder" to set {fType, nExt} to ({file type, name extension} of file mycurrentfile)
    if (fType is "PDF ") or (nExt is "pdf") then
        -- Open mycurrentfile with Acrobat
        tell application "Adobe Acrobat Pro"
        ...     
    else
        -- Open mycurrentfile with something else
        tell application "Preview"
        ...
    end if
    

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      • 2011-10-03
      相关资源
      最近更新 更多