-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathElementScripter.scpt
114 lines (90 loc) · 2.8 KB
/
ElementScripter.scpt
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
//Compiled to application with Automator.
//SIMULATE EXIT-SUB WITH BREAK:
Script: {
//Setup app for notifications.
var app = Application.currentApplication()
app.includeStandardAdditions = true
//Setup system element processing.
var system = Application('System Events')
system.includeStandardAdditions = true
var processes = system.processes()
var procTitles = []
for (var i = 0; i<processes.length; i++){
if (processes[i].title() != null) {
procTitles.push(i+1 + ': ' + processes[i].title())
}
}
var procName = system.chooseFromList(procTitles,{ withPrompt: 'Which application do you want to analyse?' })[0]
if (procName == undefined){
//EXIT-SUB
break Script
}
for (var i = 0; i<processes.length; i++){
if (i+1 + ': ' + processes[i].title() == procName) {
var proc = processes[i]
break
}
}
//Get correct window
var windows = proc.windows()
if (windows.length > 1){
var wndTitles = []
for (var i = 0; i<windows.length; i++){
if (proc.windows[i].title() != null) {
wndTitles.push(i+1 + ': ' + proc.windows[i].title())
}
}
var wndName = system.chooseFromList(wndTitles,{ withPrompt: 'Which window do you want to analyse?' })[0]
if (wndName == undefined){
//EXIT-SUB
break Script
}
for (var i = 0; i<windows.length; i++){
if (i+1 + ': ' + proc.windows[i].title() == wndName) {
var wnd = proc.windows[i]
break
}
}
//Remove "\d: " from start of wndName
wndName = wndName.substr(3)
} else if(windows.length == 1){
var wnd = proc.windows[0]
try {
var wndName = wnd.title()
} catch(e) {
wndName = procName
}
} else {
//Notify user that this may take a while
app.displayNotification('Cannot find any windows of process ' + procName, {
withTitle: 'Element Scripter',
//subtitle: 'Subtitle',
soundName: 'Sosumi'
})
//EXIT-SUB
break Script
}
//Notify user that this may take a while
app.displayNotification('Gathering GUI Elements from window "' + wndName + '" of process "' + procName + '". This may take a while...', {
withTitle: 'Element Scripter',
//subtitle: 'Subtitle',
soundName: 'Sosumi'
})
var elements = wnd.entireContents()
var a = []
var s = "Address|Title|Name|Description|Help|Role|Enabled|Focused|Position|Size|Value"
for(var i=0;i<elements.length;i++){
var el = elements[i]
s = s + "\n" + [Automation.getDisplayString(el),el.title(),el.name(),el.description(),el.help(),el.role(),el.enabled(),el.focused(),el.position(),el.size(),el.value()].join("|")
}
var textEdit = Application("TextEdit");
var newDoc = textEdit.Document().make();
newDoc.text = s
app.displayNotification('Elements from window "' + wndName + '" of process "' + procName + '" have been extracted into text edit.', {
withTitle: 'Element Scripter',
soundName: 'Sosumi'
})
//EXIT-SUB
break Script
//END-OF-SCRIPT
}