-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathAppleScriptPerformScript.calc
99 lines (89 loc) · 2.93 KB
/
AppleScriptPerformScript.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
98
99
Let([
_script_name = script_name;
_field_name_full = result_field_name;
_callback_script_name = callback_script_name;
_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 " & _result_default & "¶
¶
-- Perform designated script¶
tell application \"" & _filemaker_version & "\"¶" &
If ( restart_file ;
" close database \"" & _file_name & "\"¶
delay 5¶
open file \"" & _file_path & "\"¶
-- Pause until file is finished launching¶
repeat¶
try¶
setField(\"" & _file_name & "\",\"" & _table_name & "\",\"" & _field_name & "\", _result)¶
exit repeat¶
end try¶
end repeat¶"
) &
" tell database \"" & _file_name & "\"¶
try¶
do script \"" & _script_name & "\"¶
on error _errorText number _errorNumber¶
set _result to (\"Error \" & _errorNumber & \": \" & _errorText) as text¶
end try¶
end tell¶
end tell¶
delay 1¶
¶
-- Store result in designated global field¶
setField(\"" & _file_name & "\",\"" & _table_name & "\",\"" & _field_name & "\", _result)¶
¶
-- Perform callback script¶
tell application \"" & _filemaker_version & "\"¶
tell database \"" & _file_name & "\"¶
do script \"" & _callback_script_name & "\"¶
end tell¶
end tell¶
¶
------------------------------------------------¶
-- 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:
app.performScript ( script_name; result_field_name; callback_script_name; restart_file )
PURPOSE:
Generates AppleScript script.
When performed, AppleScript will perform designated FileMaker script, then the callback script.
AppleScript output (error messages) sent to designated global field.
DEPENDENCIES:
Requires Mac OS to run AppleScript
HISTORY:
Created: 2010-May-25 18h00 PST — Donovan A. Chandler
Modified: 2011-May-02 14h13 PST — Donovan Chandler
TO DO:
- Fix error preventing global result field from being found
- Add support for parameters (using name of global field?)
- Consider bBox plugin instead if using parameters and returns
*/