/
Handler-Tester.applescript
63 lines (55 loc) · 1.74 KB
/
Handler-Tester.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
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use kl : script "Kevin's Library"
tell application "Keyboard Maestro Engine"
if variable "SD__theChoice" exists then
set handlerName to getvariable "SD__theChoice"
else
tell application "Script Debugger"
tell front document
set theselection to selection
if theselection begins with "on" then
set handlerName to kl's extractBetween(paragraph 1 of theselection, "on ", "(")
end if
end tell
end tell
end if
end tell
tell application "Script Debugger"
tell front document
set theName to name
set theHandler to first script handler whose name is handlerName
set theparams to every handler parameter of theHandler
set handlerCall to missing value
if (count of every handler parameter of theHandler) > 0 then
repeat with n from 1 to (count of theparams)
if n = 1 then
set paramList to name of item n of theparams
set variableSetter to "set " & name of item n of theparams & " to var" & n
else
set paramList to paramList & ", " & name of item n of theparams
set variableSetter to variableSetter & return & "set " & name of item n of theparams & " to var" & n
end if
end repeat
end if
if handlerCall ≠ missing value then
set handlerCall to handlerName & "(" & paramList & ")"
set theTester to variableSetter & "
tell application \"Script Debugger\"
tell document \"" & theName & "\"
" & handlerCall & "
end tell
kend tell"
else
set theTester to "tell application \"Script Debugger\"
tell document \"" & theName & "\"
" & handlerName & "()" & "
end tell
end tell"
end if
end tell
set d to make new document with properties {source text:theTester}
tell d
compile
end tell
end tell