FileMaker:批量更改表的发生源

时间:2011-04-23 14:40:05

标签: applescript filemaker

是否有任何方法(或有任何工具)将表事件的来源从本地文件批量更改为外部源文件?

情况:我管理一个托管数据库,其数百个表出现次数大约为15个表。我的一些用户通过慢速互联网连接访问数据库。虽然需要为整个工作组更新许多表,但其他表和UI信息的一些数据大多是静态的。

我想获取数据库的副本,将必须从本地文件源共享的表的表出现更改为(现有服务器的)外部源。我可以手动执行此操作,但是它需要数千次点击并且容易出现不准确。如果我可以自动化这个过程,那就更好了。 (例如,指定我的销售表的所有出现都从本地文件移动到外部源。)

我意识到,如果没有更好的方法,我可能会使用AppleScript的UI脚本。

1 个答案:

答案 0 :(得分:2)

到目前为止还没有答案,所以我昨天写了这个。这是肮脏的,啰嗦的,并没有发现错误,但它会完成工作,并且是为未来建立起来的。

--to prepare to run this script, you should already have the External Data Source set up
--you should also open the Manage > Database menu and select the "Relationships" tab

--set newDataSource to the name of the new external data source
set newDataSource to "" 

--obtain tableOccurrences from TableNames ( Get ( FileName ) ) in the Data Viewer and copy the list into the tableOccurrences variable below
--note that tableOccurrences will be a return-separated list which is quite long when set
set tableOccurrences to ""

--a list of which tables should be moved from the local file to the hosted file. Note that these should be proper table names not table occurrences
set tablesToReplace to {"table1", "table2", ..., "tableN"}

tell application "FileMaker Pro Advanced"
    activate
end tell

set AppleScript's text item delimiters to {return}
set j to the number of text items of tableOccurrences

repeat until j < 1
    tell application "System Events"
        tell application Process "FileMaker Pro Advanced"
            keystroke text item j of tableOccurrences
            keystroke "o" using command down
            delay 1

            set i to 1
            repeat until ((i > (count of rows of table 1 of scroll area 1 of window 1)) or selected of row i of table 1 of scroll area 1 of window 1)
                set i to i + 1
            end repeat

            if (i <= (count of rows of table 1 of scroll area 1 of window 1) and name of static text of row i of table 1 of scroll area 1 of window 1 is in tablestoReplace) then
                set currentMasterTable to name of static text of row i of table 1 of scroll area 1 of window 1
                set currentOccurrenceName to value of text field 1 of window 1
                click pop up button 1 of window 1
                tell menu 1 of pop up button 1 of window 1
                    click menu item newDataSource
                end tell

                set k to 1
                set tableSelected to false
                repeat until tableSelected or k > (count of rows of table 1 of scroll area 1 of window 1)
                    if name of static text of row k of table 1 of scroll area 1 of window 1 = currentMasterTable then
                        select row k of table 1 of scroll area 1 of window 1
                        set tableSelected to true
                    end if
                    set k to k + 1
                end repeat

                set value of text field 1 of scroll area 1 of window 1 to currentOccurrenceName
                click button "OK" of window 1
            else
                click button "Cancel" of window 1
            end if
        end tell
    end tell
    set j to j - 1
end repeat