在全局字段中嵌入Applescript(使用Acrobat导出容器和触发器打印)

时间:2014-06-24 22:10:25

标签: pdf applescript acrobat filemaker

我正在尝试将一个文件制作器脚本绑定到一个临时空间并使用和苹果脚本打印它们。

我能够从这个和其他一些板上剔除信息来创建一个AppleScript,它将使用Acrobat从文件夹中打印PDF。

我已经创建了一个脚本,可以找到相关附件并将它们导出到桌面。

我遇到麻烦的是合并两者。

我需要将PDF导出到文件夹或临时位置并触发苹果脚本以启动打印...

这个伟大的建议是由Chival of chivalrysoftware.com/... ...

提供的

通过将文件名附加到Get(TemporaryPath)来计算要导出的位置。 将容器字段内容导出到FileMaker到该路径。 将路径保存到FileMaker中的全局字段 使用嵌入式AppleScript访问全局字段路径 使用AppleScript在预览中打开文件并打印

这是我的苹果脚本:

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
end batchprint

我的Filemaker脚本是:

Go to Related Record[
    Show only related records; From table: 'Attachments";
    Using layout: "Attachements Report' (Attachments); New window
]
Enter Find Mode 
Constrain Found Set [Restore]
Sort Records [Restore; No dialog]
# After finding the related attachments and constraining them to the specific type
# we rename and export them to the desktop
Go to Record/Request/Page [First] 
Loop
    Set Variable [$Path; Value:
        Get ( DesktopPath ) & Attachments::Record number & "-"
            & Attachment Type List 2::Prefix_z & Lien::Lien_ID_z1]
    Export Field Contents [Attachments::file_c; $Path]
    Go to Record/Request/Page [Next: Exit after last] 
End Loop 
Close Window [Current Window] 

1 个答案:

答案 0 :(得分:0)

首先,FileMaker部分。在其中一个表中创建一个全局文本字段。看起来Attachments表最适合它。我将此称为g_applescript_parameter

现在我们要使用您的$Path变量,因为您提供的计算结果应该类似/Aslan/Users/chuck/Desktop/1234-ABC4321。我建议您添加.pdf,因为您要导出PDF文件。这可能会有所帮助。

另外,我建议您使用Get( TemporaryPath )代替Get( DesktopPath )。当您退出FileMaker时,您放置在临时文件夹中的任何内容都将被自动删除,这意味着您以后不必编写任何内容来清理桌面文件夹,也不必手动删除它们。让FileMaker为您完成这项工作。 :)

无论如何,FileMaker使用filemac:/volumeName/directoryName/fileName形式的路径(请参阅{{1>}脚本步骤的指定输出文件对话框中的注释)。因此,您还应该将Export Field Contents添加到路径变量的开头。

总而言之,你的filemac:应该设置为:

$Path

因此,FileMaker的导出路径现在应该更好。但AppleScript要求使用不同格式的同一文件的路径。鉴于上述情况,AppleScript的版本应该类似于"filemac:" & Get( DesktopPath ) & Attachments::Record number & "-" & Attachment Type List 2::Prefix_z & Lien::Lien_ID_z1 & ".pdf" 。换句话说,驱动器名称后的所有内容。幸运的是,FileMaker可以使用/Users/chuck/Desktop/1234-ABC4321.pdf函数获取驱动器名称。对我来说,该函数返回Get( SystemDrive )。因此,如果我们采用上面定义的/Aslan/变量并移除$Path,并按filemac: 定义的驱动器名称在开头添加一个额外的斜杠,这会将我们的FileMaker路径转换为AppleScript路径:

Get( SystemDrive )

使用"/" & Substitute( $Path; "filemac:" & Get( SystemDrive ); "" ) 创建Set Variable变量并将其设置为上述内容。

现在在你的循环中存储该全局文本字段中$ASPath变量的内容:

$ASPath

现在AppleScript可以提取该信息。我假设给定一个准确的文件传递给Loop Set Variable[ $Path; …] Set Variable[ $ASPath; …] Set Field[Attachments::g_applescript_parameter; $ASPath) Export Field Contents[Attachments::file_c; $Path] Go to Record/Request/Page[Next; Exit after last] End Loop 函数,batchprint将起作用,所以保留它,但删除它之前的所有内容并使用类似的东西:

batchprint

set _pdf_path to contents of cell "g_applescript_parameter" of current layout batchprint(_pdf_path) on batchprint(mycurrentfile) ... end batchprint 步骤后添加Perform AppleScript步骤,并将上述代码放入其中。

请注意,上述AppleScript的第一行只能在FileMaker中编写。如果你在FileMaker之外进行测试,例如,在脚本编辑器中,那么你需要先读取第一行

Export Field Contents

您不需要在tell applicaiton "FileMaker" to set _pdf_path ... 脚本步骤中执行此操作,因为默认情况下命令会发送到封闭的FileMaker应用程序。