forked from DonovanChan/fmfunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppleScriptPerformScripts.calc
97 lines (89 loc) · 2.82 KB
/
AppleScriptPerformScripts.calc
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
Let([
_script_names = scriptNameList ;
_field_name_full = resultFieldName;
_filemaker_version =
Case (
PatternCount ( Get ( ApplicationVersion ) ; "ProAdvanced" ); "FileMaker Pro Advanced";
"FileMaker Pro"
) ;
_path = Get ( FilePath ) ;
_file_name = Middle ( path ; Position ( path ; "/" ; Length ( path ) ; -1 ) + 1 ; 999 ) ; _file_path = FilePathForAppleScript ( Get ( FilePath ) );
_field_name_full_list = Substitute( _field_name_full; "::"; ¶ );
_table_name = GetValue( _field_name_full_list; 1 );
_field_name = GetValue( _field_name_full_list; 2 );
_result_default = 0
];
"-- Define vars¶
set _result to 0¶
set scriptText to \"" & _script_names & "\"¶
set scriptList to paragraphs in scriptText¶
set dbName to \"" & _file_name & "\"¶
¶
-- Loop thru scripts¶
repeat with scriptCur in scriptList¶
tell application \"" & _filemaker_version & "\"¶" &
If ( restartFile ;
" close database dbName¶
delay 5¶
open file \"" & _file_path & "\"¶
¶
-- Pause until file is finished launching¶
repeat¶
try¶
setField(\"" & _file_name & "\",\"" & _table_name & "\",\"" & _field_name & "\", _result)¶
exit repeat¶
on error _errorText number _errorNumber¶
if _errorNumber is not equal to -1708 then¶
display alert \"Error\" message _errorNumber & \": \" & _errorText¶
end if¶
end try¶
end repeat¶"
) &
" ¶
tell database dbName¶
try¶
do script scriptCur¶
on error _errorText number _errorNumber from _object to _to¶
_object¶
set _result to (\"Error \" & _errorNumber & \": \" & _errorText & return & ¦
\"Expected Type: \" & _to) as text¶
end try¶
end tell¶
end tell¶
delay 1¶
¶
-- Store result in designated global field¶
setField(\"" & _file_name & "\",\"" & _table_name & "\",\"" & _field_name & "\", _result)¶
¶
end repeat¶
¶
------------------------------------------------¶
-- HANDLERS¶
------------------------------------------------¶
¶
---- FileMaker Handlers ----¶
------------------------------------------------¶
¶
-- Handler: Sets FileMaker field value¶
on setField(databaseName, tableName, fieldName, theValue)¶
tell application \"" & _filemaker_version & "\"¶
tell database (databaseName as text)¶
tell table (tableName as text)¶
set field fieldName to theValue¶
end tell¶
end tell¶
end tell¶
end setField"
)
/* —————————————————————————————— //
NAME:
AppleScriptPerformScripts ( scriptNameList ; resultFieldName ; restartFile )
PURPOSE:
Generates AppleScript script.
When performed, AppleScript will perform designated FileMaker scripts in succession.
AppleScript output (error messages) sent to designated global field.
DEPENDENCIES:
Requires Mac OS to run AppleScript
HISTORY:
Created: 2011-May-04 19h46 PST — Donovan A. Chandler
*/