forked from petrowsky/fmpfunctions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.execute.fmfn
84 lines (64 loc) · 3.21 KB
/
script.execute.fmfn
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
/*
* =====================================================
* script.execute( method; file; script; parameter; control )
*
* RETURNS: (bool) Result of the execution of a script.
* DEPS: At least one Script triggering plugin.
* Supported are SmartPill PHP plugin, zippScript & DoScript
* NOTES:
* =====================================================
*/
If ( Get ( WindowMode ) = 0;
Let([
//------------------------- VARIABLES
_Default = "sm"; // Set your default script plugin here
_File = If (IsEmpty(file); Get(FileName); file);
_Control = If (IsEmpty(control); "pause"; control);
method = If (IsEmpty(method); _Default; method);
_Error = Case(
method = "zipp"; Get ( ScriptName ) = script or Let ( [ _Result = zippScript_PerformScript( _File; script; parameter; _Control );
$$SCRIPT.TEXT = Case(
_Result = "" ; "" ;
_Result = "$$-1" ; "Incorrect number of parameters" ;
_Result = "$$-2" ; "Unknown control parameter code" ;
_Result = "$$100" ; "File is missing (named file not open)" ;
_Result = "$$104" ; "Script is missing (no script of that name)")
]; "" );
method = "dosc"; Get ( ScriptName ) = script or mFMb_DoScript( script ; _File ; parameter ; _Control ) & mFMb_DS_LastErrNum;
method = "sm"; Get ( ScriptName ) = script
or
EvaluateGroovy(
Substitute (
"fmpro.performScript( ':file', ':script', \":parameter\" )";
[":file"; Get( FileName )];
[":script"; script];
[":parameter"; Substitute ( parameter; ["\""; "\\\""]; [ ¶; "\r"]; [ "$"; "\$"] )]
)
);
method = "php";
Let([
//------------------------- VARIABLES
_Control = If ( IsEmpty (control);
3; // 3 is the value used by fm_perform_script for pause
Let( val = Left( control; 4); Int( Position ( "halt exit resu paus " ; val ; 1 ; 1 ) / 5 ) ) );
_PHPCode = "print fm_perform_script("
& Quote( _File ) & ", "
& Quote( script ) & ", "
& Quote( parameter ) & ", "
& _Control &
");";
$$SCRIPT_RESULT = Get ( ScriptName ) = script or PHP_Execute( _PHPCode )
];
//------------------------- RESULT
0 // I haven't put error trapping in yet. :(
);
0
)
];
If ( _Error;
Let( $$SCRIPT.ERROR = _Error; 1 )
)
)
)
// Thanks Koen Van Hulle for the window mode suggestion
// Thanks Peter Wagemans for the "aha" in logic for testing for the name of the currently running script and the error trapping