-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathLIB_FileMaker.applescript
183 lines (173 loc) · 6.27 KB
/
LIB_FileMaker.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
---------------------------------------------
-- SCRIPT LIBRARY: FILEMAKER
---------------------------------------------
-- HANDLER: Prompt user for file
on promptForDatabase(dbList)
tell application "Finder"
set _db_selected to choose from list dbList with prompt "Select database:"
end tell
end promptForDatabase
-- HANDLER: Returns list of all values for a specified field
-- Use document class to retrieve values for found set only
on getFieldValues(theDatabase, tableName, fieldName)
tell application "FileMaker Pro Advanced"
tell database (theDatabase as text)
field (fieldName as text) of table (tableName as text)
end tell
end tell
end getFieldValues
-- HANDLER: Sets FileMaker field value
-- Be sure to include extension if you have periods in file name
-- tableName = basetable, not the table occurrence
on setField(databaseName, tableName, fieldName, theValue)
-- Calculate application name when generating script for users on Pro
-- Or, just use `tell application me`
tell application "FileMaker Pro Advanced"
tell database (databaseName as text)
tell table (tableName as text)
set field fieldName to theValue
end tell
end tell
end tell
end setField
-- HANDLER: Performs script, sets result to global field, then performs callback script
-- Required handlers: splitFieldName()
on performScript(databaseName, scriptName, resultFieldNameFull, callbackScriptName)
tell application "FileMaker Pro Advanced"
tell database databaseName
set _result to ""
try
do script scriptName
on error _errorText number _errorNumber from _object partial result _partial to _to
set _result to ("Error " & _errorNumber & ": " & _errorText & return & ¬
"Object: " & _object & return & ¬
"Expected Type: " & _to & return & ¬
"Partial Result: " & _partial) as text
end try
end tell
end tell
-- Ensure process is complete
delay 1
-- Store result in designated global field
tell application "FileMaker Pro Advanced"
tell database databaseName
if resultFieldNameFull is not "" then
set _result_field_items to my splitFieldName(resultFieldNameFull)
set _result_table to item 1 of _result_field_items
set _result_field to item 2 of _result_field_items
tell table _result_table
set field _result_field to _result
end tell
end if
if callbackScriptName is not "" then
do script callbackScriptName
end if
end tell
end tell
end performScript
-- HANDLER: Splits fully qualified field name into array {table,field}
to splitFieldName(fullyQualifiedFieldName)
set _delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "::"
set _field_items to fullyQualifiedFieldName's text items
set AppleScript's text item delimiters to _delim
if (count of _field_items) < 2 then
display dialog "Error: Please specify the table within this field name: " & fullyQualifiedFieldName
error
else
return _field_items
end if
end splitFieldName
-- HANDLER: Returns list of open FileMaker databases
on getOpenDatabases()
tell application "FileMaker Pro Advanced"
set _file_list to {}
copy number of databases to _file_count
if _file_count = 0 then
display dialog "There are no FileMaker databases open!" buttons "Ok" with icon stop giving up after 5
else
repeat with _file_cur from 1 to _file_count
--get name of each file
copy name of database _file_cur to end of _file_list
end repeat
end if
_file_list
end tell
end getOpenDatabases
-- HANDLER: Returns list of script names for specified FileMaker document
on getScriptNames(theDatabase)
tell application "FileMaker Pro Advanced"
set myTblNum to 1
set myDB to theDatabase
set myScriptList to {}
set myScriptIdList to {}
set myScriptCount to the count of every FileMaker script
if myScriptCount > 1 then
set myScriptIdList to the ID of every FileMaker script
repeat with i from 1 to the count of myScriptIdList
set myScriptItem to the name of FileMaker script ID (item i of myScriptIdList) of database myDB
set myScriptList to myScriptList & myScriptItem & tab
set i to i + 1
end repeat
myScriptList
else
if myScriptCount = 1 then
set myScriptName to the name of FileMaker script 1 of database myDB
else
set myScriptName to ""
end if
myScriptName
end if
end tell
end getScriptNames
-- HANDLER: Returns list of table names of frontmost FileMaker file
on getTableNames()
tell application "FileMaker Pro Advanced"
set myTableList to {}
copy number of tables to mytblcount
if mytblcount = 0 then
display dialog "There are no FileMaker 7 databases open!" buttons "Ok" with icon stop giving up after 5
else
repeat with tblLoop from 1 to mytblcount
--get name of each table
copy name of table tblLoop to end of myTableList
end repeat
end if
myTableList
end tell
end getTableNames
-- HANDLER: Converts xml text to FileMaker clipboard format
--Parameters: clipText, outputFormat [script|script_step|table|field|custom_function]
--Methodology: Write text to temp file so that it can be converted from file
--Formats:
-- XMSC for script definitions
-- XMSS for script steps
-- XMTB for table definitions
-- XMFD for field definitions
-- XMCF for custom functions
on convertClip(clipText, outputFormat)
set temp_path to (path to temporary items as Unicode text) & "FMClip.dat"
set temp_ref to open for access file temp_path with write permission
set eof temp_ref to 0
write clipText to temp_ref
close access temp_ref
if outputFormat is "script" then
set clipTextFormatted to read file temp_path as «class XMSC»
else if outputFormat is "script_step" then
set clipTextFormatted to read file temp_path as «class XMSS»
else if outputFormat is "table" then
set clipTextFormatted to read file temp_path as «class XMTB»
else if outputFormat is "field" then
set clipTextFormatted to read file temp_path as «class XMFD»
else if outputFormat is "custom_function" then
set clipTextFormatted to read file temp_path as «class XMCF»
end if
return clipTextFormatted
end convertClip
-- HANDLER: Creates text string as FileMaker name-value pair
on fmhash(name, value)
set searchList to [":", "=", ">", "<"]
set replaceList to ["/:", "/=", "/>", "/<"]
return "<:" & my searchReplaceText(name, searchList, replaceList) & ¬
":=" & searchReplaceText(value, searchList, replaceList) & ":>"
end fmhash