确定文件类型并选择正确的程序来打开和打印文件

确定文件类型并选择正确的程序来打开和打印文件

本文介绍了Applescript(如果/那么)确定文件类型并选择正确的程序来打开和打印文件(在批处理序列内)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在@chuck 和其他论坛帖子的大力帮助下,我整理了一个苹果脚本,以有效地批量打印从 filemaker 容器导出的文件列表到我桌面上一个名为print"的文件夹.

I have culled together an applescript with great help from @chuck and other board posts to effectively batch print a list of files exported from filemaker containers to a folder called "print" on my desktop.

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

The problem I'm running into now is some of those container exports are not PDF (its a mix of Jpg, PNG, Tif and PDF) and will not open using acrobat (using preview for the PDF or any other PDF viewer is out of the question for a myriad of reasons)... This problem is effectively shutting down the work flow because of error messages from acrobat that must be manually clicked off before the script will proceed to the next file.

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

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

(i.e. if .pdf then use acrobat print close window, if not use preview to open file, print close window, repeat until all files have been printed.)

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

Below is my current working code.(FYI) This script is running within a filemaker script that is creating the "Print" folder on the desktop and exporting the container fields to the folder.

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

设置 myfiles 列出文件夹 myFolder 不可见

与 myfiles 中的 myfile 重复

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

结束重复

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

结束批量打印`

推荐答案

使用 Finder 测试文件类型和扩展名,然后使用您的 Acrobat 告诉块它是否是 pdf,如果它不是,则使用预览或其他任何方式.下面是代码结构:

Use Finder to test for the file type and the extension, then use your Acrobat tell block if it's a pdf, and use Preview or whatever if it is not.Here's the code structure for that:

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

这篇关于Applescript(如果/那么)确定文件类型并选择正确的程序来打开和打印文件(在批处理序列内)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 20:35