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



我正在尝试将一个文件制作脚本连接在一起,该脚本将导出pdf文件到临时空间,并使用apple脚本打印它们。

我能够从这个和其他一些板中收集信息来创建一个applescript,它将使用Acrobat从文件夹中打印pdf。

我已经创建了一个脚本,用于查找相关附件并将其导出到桌面。

我遇到的问题是如何将两者合并。

我需要将PDF导出到文件夹或临时位置,并触发apple脚本启动打印…

这个伟大的建议是由chivalrysoftware.com/......的Chuck提供的

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

这是我的苹果脚本:
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] 

首先是FileMaker部分。在其中一个表中创建一个全局文本字段。看起来Attachments表是它的最佳位置。我把它命名为g_applescript_parameter

现在我们将使用$Path变量,根据您提供的calc应该是/Aslan/Users/chuck/Desktop/1234-ABC4321之类的东西。我建议在它的末尾附加一个.pdf,因为你将导出PDF文件。这可能对以后有所帮助。

另外,我建议您使用Get( TemporaryPath )而不是Get( DesktopPath )。当你退出FileMaker时,你放在临时文件夹中的任何东西都会被自动删除,这意味着你不需要写任何东西来清理桌面文件夹,也不需要手动删除它们。让FileMaker为您完成这项工作。:)

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

总而言之,你的$Path应该设置成这样:
"filemac:" & Get( DesktopPath ) & Attachments::Record number & "-" &
    Attachment Type List 2::Prefix_z & Lien::Lien_ID_z1 & ".pdf"

所以你的导出路径为FileMaker现在应该工作得更好。但是AppleScript对同一个文件的路径要求不同的格式。鉴于上述情况,AppleScript的版本应该是类似/Users/chuck/Desktop/1234-ABC4321.pdf的。换句话说,就是驱动器名之后的所有内容。幸运的是,FileMaker可以通过Get( SystemDrive )函数获得驱动器名称。对我来说,该函数返回/Aslan/。因此,如果我们采用上面定义的$Path变量,并删除filemac:和由Get( SystemDrive ) 定义的驱动器名称,并在开头添加额外的斜杠,这将把我们的FileMaker路径转换为AppleScript路径:

"/" & Substitute( $Path; "filemac:" & Get( SystemDrive ); "" )

使用Set Variable创建一个$ASPath变量,并将其设置为上述值

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

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

现在AppleScript可以提取这些信息了。我假设给定一个准确的文件被传递给batchprint函数,batchprint将工作,所以保持它,但在它之前删除一切,并使用这样的东西:

set _pdf_path to contents of cell "g_applescript_parameter" of current layout
batchprint(_pdf_path)
on batchprint(mycurrentfile)
    ...
end batchprint

Export Field Contents步骤之后添加Perform AppleScript步骤,并将上述代码放入其中

注意,上面AppleScript的第一行只能在FileMaker中编写。如果你在FileMaker之外测试,例如在Script Editor中,那么你需要将第一行设置为

tell applicaiton "FileMaker" to set _pdf_path ...

Perform AppleScript脚本步骤中不需要这样做,因为默认情况下命令被发送到封闭的FileMaker应用程序。

最新更新