"current record" 不起作用:applescripting Filemaker Pro 13 循环

"current record" doesn't work: applescripting Filemaker Pro 13 in a loop

我有一个 Pro 13 database with around 120 records (it's for a conference). I want to team it up with BBEdit to create individual files for each abstract, thus 。令我惊讶的是(尽管有很多关于脚本的网络提示)“[tag:current record]”在脚本中无法识别。

相关位是这样的:

FM Script:
Loop
Perform Applescript

tell application "FileMaker Pro"
activate
set MyFileName to cell "WebAbstractFileName" of table "SelectionProcess"
set MyWebAbstract to cell "WebAbstract" of table "SelectionProcess" as text
end tell

-- (BBEdit bit, which works fine in testing)

 Go to Next Record (exit after last)
End Loop

如果我只想检索第一条记录,这很好用!

这个 applescript 是在一个 filemaker 脚本中设置的,它循环遍历记录,但脚本不关心它在哪条记录中。

我试过在 table 引用之前添加 'of current record' 但它会给我错误(例如错误 "FileMaker Pro got an error: Object not found." 来自当前记录的单元格 "WebAbstractFileName" 的数字 -1728 table "SelectionProcess") 没有 'current record' 它工作正常,但只给了我第一条记录。

更多的修补解决了这个问题。关键是改变语法。脚本现在显示为:

tell application "FileMaker Pro"
activate

tell current record to set MyFileName to cell "WebAbstractFileName"
tell current record to set MyWebAbstract to cell "WebAbstract"


end tell

似乎发生的是字段必须是可见的(但我认为这在某一时刻不是问题......去想一想。如果它们是可见的,你可以放弃 table 规范).此脚本包含在循环块中,将作用于搜索结果并(如果有指示)在最后一条记录后退出。

我附加了 脚本来创建一个新文件,并使用从另一个字段中获取的变量保存它,以备不时之需。

tell application "BBEdit"
set notesPath to ":Users:ophiochos:Dropbox:TL Conference Admin:Webpage materials:Abstracts:"

set newFilePath to notesPath & MyFileName & ".html"

set newDoc to make new text document with properties {contents:MyWebAbstract}

tell newDoc
    set source language to "HTML"
    save to newFilePath
    close window
end tell
end tell

以下是(大致)如何在 Filemaker 脚本中执行此操作:

Go to Layout [ “YourTable” ] 
# FIND THE RECORDS OF INTEREST
Perform Find [ Restore ] 
Go to Record/Request/Page [ First ] 
Loop 
    New Window [  ] 
    # ISOLATE THE CURRENT RECORD
    Show All Records 
    Omit Record 
    Show Omitted Only 
    Set Variable [ $path; Value:Get ( DocumentsPath ) & "someFolder/"  & YourTable::Somefield  & ".html" ] 
    Export Records [ No dialog; “$path” ] 
    Close Window [ Current Window ] 
    Go to Record/Request/Page [ Next; Exit after last ] 
End Loop 

这会将搜索结果中的每条记录作为单独的文件导出到位于用户文档文件夹中的文件夹 "someFolder" 中,使用 YourTable::Somefield 字段的内容作为文件名。

如果像您所说的那样不需要单独的文件,那么这当然可以简单得多。

或者您可以简单地创建一个计算字段,其中包含每条记录所需的导出文件的内容,一条一条地循环记录,然后只使用 Export Field Contents ['YourCalculatedField_c'] 脚本步骤。

您还可以使用 FM 预览 html 输出,方法是使用网络查看器显示您的 html。这与单独导出一起,您无需外部程序即可获得所有这些功能。

如果您需要更改输出文件的文本编码,您也可以在用于输出文件的 xslt 中指定: http://filemakerhacks.com/2012/09/23/export-field-contents-as-utf-8/

此外,如果从 FileMaker 中执行 applescript,则不需要 "tell application" 行,因为它是隐含的。