gui_inspect 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -5
- data/exe/gui_inspect +18 -0
- data/lib/env.rb +41 -0
- data/lib/gui_inspect/inspector.rb +73 -0
- data/lib/gui_inspect/version.rb +9 -0
- data/lib/gui_inspect.rb +95 -0
- metadata +7 -5
- data/exe/get_ui_elements +0 -85
- data/lib/gui/version.rb +0 -5
- data/lib/gui.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d13fe746824b34ca73991a576d5e7df2b789f3b73ea74def254ef615529763da
|
4
|
+
data.tar.gz: ce3c26ada39119195f645c5cff6b5ccd5e0ff36d7a81bb597715af4b5e165e4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88565fb81632f58a71fb8ec2122df174065182a892f6028404097174e94f92fcd741138195deae2fe28ca0721a93624a9c3b2da14eeb377fba4a47a99dd1af33
|
7
|
+
data.tar.gz: f44548dd63ded4d32a43d4962aaede4ff455d5c847fc0a7663da5b256e3e6c2e6fee970541ccfeb873f0e8bde48502cf4995a1e14ede66129c46a2f6323d28d7
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# GUI Inspect
|
2
2
|
|
3
3
|
Simple methods to inspect the GUI elements of a running MacOS application.
|
4
4
|
|
@@ -7,19 +7,21 @@ Simple methods to inspect the GUI elements of a running MacOS application.
|
|
7
7
|
Install the gem and add to the application's Gemfile by executing:
|
8
8
|
|
9
9
|
```bash
|
10
|
-
bundle
|
10
|
+
bundle gui_inspect
|
11
11
|
```
|
12
12
|
|
13
13
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
14
|
|
15
15
|
```bash
|
16
|
-
gem install
|
16
|
+
gem install gui_inspect
|
17
17
|
```
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
>
|
22
|
-
|
21
|
+
> gui_inspect processes # Generates a list of current active processes
|
22
|
+
|
23
|
+
> gui_inspect elements '<application name>' >path/to/file # Generates a list of the GUI elements of
|
24
|
+
# this application in its current state
|
23
25
|
|
24
26
|
## Development
|
25
27
|
|
data/exe/gui_inspect
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Main executable for gui_inspect script
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler/setup'
|
7
|
+
require_relative '../lib/env'
|
8
|
+
if Environment.non_production?
|
9
|
+
require 'pry'
|
10
|
+
require 'pry-stack_explorer'
|
11
|
+
require 'pry-byebug'
|
12
|
+
end
|
13
|
+
|
14
|
+
require_relative '../lib/gui_inspect'
|
15
|
+
|
16
|
+
if __FILE__ == $0
|
17
|
+
GUIInspect::CLI.go(ARGV)
|
18
|
+
end
|
data/lib/env.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Determine the current environment (i.e. development, test, or production)
|
2
|
+
|
3
|
+
module Environment
|
4
|
+
class << self
|
5
|
+
def current_git_branch
|
6
|
+
`git branch --show-current`.chomp
|
7
|
+
end
|
8
|
+
|
9
|
+
def current
|
10
|
+
current_environment = ENV['RAILS_ENV'] || ENV['RACK_ENV']
|
11
|
+
unless current_environment
|
12
|
+
current_environment = current_git_branch == 'master' ? 'production' : 'development'
|
13
|
+
end
|
14
|
+
current_environment.downcase.to_sym
|
15
|
+
end
|
16
|
+
|
17
|
+
def production?
|
18
|
+
current == :production
|
19
|
+
end
|
20
|
+
|
21
|
+
def non_production?
|
22
|
+
!production?
|
23
|
+
end
|
24
|
+
|
25
|
+
def test?
|
26
|
+
current == :test
|
27
|
+
end
|
28
|
+
|
29
|
+
def non_test?
|
30
|
+
!test?
|
31
|
+
end
|
32
|
+
|
33
|
+
def development?
|
34
|
+
non_test? && non_production?
|
35
|
+
end
|
36
|
+
|
37
|
+
def non_development?
|
38
|
+
!development?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module GUIInspect
|
4
|
+
class Inspector
|
5
|
+
attr_reader :error
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
end
|
9
|
+
|
10
|
+
private def run_applescript(script)
|
11
|
+
file = Tempfile.new('gui_inspect')
|
12
|
+
output = begin
|
13
|
+
file.write(script)
|
14
|
+
file.close
|
15
|
+
`osascript #{file.path}`
|
16
|
+
ensure
|
17
|
+
file.unlink # Release the temporary script file
|
18
|
+
end
|
19
|
+
if output =~ /^Error/
|
20
|
+
@error = output.chomp
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
@error = nil
|
24
|
+
output.gsub(/,\s+/,"\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
def puts_applescript_results(script)
|
28
|
+
output = run_applescript(script)
|
29
|
+
if output
|
30
|
+
puts output
|
31
|
+
else
|
32
|
+
warn @error
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
output
|
36
|
+
end
|
37
|
+
|
38
|
+
def processes
|
39
|
+
get_processes_script = <<-END_OF_APPLESCRIPT
|
40
|
+
try
|
41
|
+
tell application "System Events"
|
42
|
+
set listOfProcesses to (name of every process where background only is false)
|
43
|
+
end tell
|
44
|
+
listOfProcesses
|
45
|
+
on error errMsg number errorNumber
|
46
|
+
"Error: " & errMsg & " (#" & (errorNumber as text) & ")"
|
47
|
+
end try
|
48
|
+
END_OF_APPLESCRIPT
|
49
|
+
puts_applescript_results(get_processes_script)
|
50
|
+
end
|
51
|
+
|
52
|
+
def elements(app)
|
53
|
+
get_elements_script = <<-END_OF_APPLESCRIPT
|
54
|
+
try
|
55
|
+
tell application "#{app}"
|
56
|
+
activate -- If nescessary, starts application. Gives it focus
|
57
|
+
end tell
|
58
|
+
delay 3
|
59
|
+
tell application "System Events"
|
60
|
+
set frontmostName to name of application process 1 whose frontmost is true
|
61
|
+
tell application process frontmostName
|
62
|
+
set uiElems to entire contents
|
63
|
+
end tell
|
64
|
+
end tell
|
65
|
+
uiElems
|
66
|
+
on error errMsg number errorNumber
|
67
|
+
"Error: " & errMsg & " (#" & (errorNumber as text) & ")"
|
68
|
+
end try
|
69
|
+
END_OF_APPLESCRIPT
|
70
|
+
puts_applescript_results(get_elements_script)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/gui_inspect.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require_relative "gui_inspect/version"
|
3
|
+
require_relative "gui_inspect/inspector"
|
4
|
+
|
5
|
+
module GUIInspect
|
6
|
+
class Error < StandardError; end
|
7
|
+
class CLI < Thor
|
8
|
+
package_name "gui_inspect"
|
9
|
+
|
10
|
+
def self.exit_on_failure?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
# Display help with additional context
|
15
|
+
def help(command = nil, subcommand: false)
|
16
|
+
say <<~END_HELP
|
17
|
+
gui_inspect
|
18
|
+
-----------
|
19
|
+
Provides a set of tools for inspecting the GUI processes and elements of a MacOS GUI
|
20
|
+
environment. This is useful as a tool to help design scripts for GUI automation.
|
21
|
+
|
22
|
+
END_HELP
|
23
|
+
super command, subcommand
|
24
|
+
end
|
25
|
+
|
26
|
+
# desc 'help', "Get help text"
|
27
|
+
# def help
|
28
|
+
# puts caller.first.inspect
|
29
|
+
|
30
|
+
# app_name = File.basename(__FILE__)
|
31
|
+
# help_text = <<-END_HELP
|
32
|
+
# | #{app_name}:
|
33
|
+
# |
|
34
|
+
# | Gather information about the elements of the graphical user interface of an application
|
35
|
+
# |
|
36
|
+
# | Usage:
|
37
|
+
# | #{app_name} '<name of GUI app>'
|
38
|
+
# |
|
39
|
+
# | #{app_name} gathers a lot of information about the named application and outputs it to
|
40
|
+
# | the standard output. (Standard output may be redirected to a file using the usual '>'
|
41
|
+
# | syntax.)
|
42
|
+
# |
|
43
|
+
# | For best results, we recommend that you have the application you want to analyze already
|
44
|
+
# | running and in the state that you want it. (For instance, displaying dialogs you're interested
|
45
|
+
# | in.) Move quickly -- this script can only capture information while it is still displayed.
|
46
|
+
# END_HELP
|
47
|
+
# puts help_text.split("\n").map { |line| line[/^\s*\|\s\s(.*)$/, 1]}.join("\n")
|
48
|
+
# end
|
49
|
+
|
50
|
+
desc 'version', "Display version"
|
51
|
+
def version
|
52
|
+
puts GUIInspect.version
|
53
|
+
end
|
54
|
+
|
55
|
+
desc 'processes', "Show the active processes"
|
56
|
+
long_desc <<-END_DESC
|
57
|
+
Gather information about the processes currently running in the GUI.\x5
|
58
|
+
\x5
|
59
|
+
Produces a list of running processes on $stdout (which may be redirected using the
|
60
|
+
usual '>' syntax). \x5
|
61
|
+
\x5
|
62
|
+
Move quickly -- this script can only capture information about processes while they are still running.
|
63
|
+
END_DESC
|
64
|
+
|
65
|
+
def processes
|
66
|
+
inspector = GUIInspect::Inspector.new
|
67
|
+
inspector.processes
|
68
|
+
end
|
69
|
+
|
70
|
+
desc 'elements APPLICATION', "Show the UI elements"
|
71
|
+
long_desc <<-END_DESC
|
72
|
+
Gather information about the elements of the graphical user interface of an application.\x5
|
73
|
+
\x5
|
74
|
+
Gathers a lot of information about the named application and outputs it to
|
75
|
+
the standard output. (Standard output may be redirected to a file using the usual '>'
|
76
|
+
syntax.)\x5
|
77
|
+
\x5
|
78
|
+
For best results, we recommend that you have the application you want to analyze already
|
79
|
+
running and in the state that you want it. (For instance, displaying dialogs you're interested
|
80
|
+
in.)\x5
|
81
|
+
\x5
|
82
|
+
Move quickly -- this script can only capture information while it is still displayed.
|
83
|
+
END_DESC
|
84
|
+
def elements(application)
|
85
|
+
inspector = GUIInspect::Inspector.new
|
86
|
+
inspector.elements(application)
|
87
|
+
end
|
88
|
+
|
89
|
+
class << self
|
90
|
+
def go(argv)
|
91
|
+
GUIInspect::CLI.start(argv)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gui_inspect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard LeBer
|
@@ -12,7 +12,7 @@ dependencies: []
|
|
12
12
|
email:
|
13
13
|
- richard.leber@gmail.com
|
14
14
|
executables:
|
15
|
-
-
|
15
|
+
- gui_inspect
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
@@ -22,9 +22,11 @@ files:
|
|
22
22
|
- LICENSE.txt
|
23
23
|
- README.md
|
24
24
|
- Rakefile
|
25
|
-
- exe/
|
26
|
-
- lib/
|
27
|
-
- lib/
|
25
|
+
- exe/gui_inspect
|
26
|
+
- lib/env.rb
|
27
|
+
- lib/gui_inspect.rb
|
28
|
+
- lib/gui_inspect/inspector.rb
|
29
|
+
- lib/gui_inspect/version.rb
|
28
30
|
- output/p_touch_editor_ui_elements.txt
|
29
31
|
- sig/gui.rbs
|
30
32
|
homepage: https://github.com/rleber/gui
|
data/exe/get_ui_elements
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'tempfile'
|
4
|
-
|
5
|
-
def help
|
6
|
-
app_name = File.basename(__FILE__)
|
7
|
-
help_text = <<-END_HELP
|
8
|
-
| #{app_name}:
|
9
|
-
|
|
10
|
-
| Gather information about the elements of the graphical user interface of an application
|
11
|
-
|
|
12
|
-
| Usage:
|
13
|
-
| #{app_name} '<name of GUI app>'
|
14
|
-
|
|
15
|
-
| #{app_name} gathers a lot of information about the named application and outputs it to
|
16
|
-
| the standard output. (Standard output may be redirected to a file using the usual '>'
|
17
|
-
| syntax.)
|
18
|
-
|
|
19
|
-
| For best results, we recommend that you have the application you want to analyze already
|
20
|
-
| running and in the state that you want it. (For instance, displaying dialogs you're interested
|
21
|
-
| in.) Move quickly -- this script can only capture information while it is still displayed.
|
22
|
-
END_HELP
|
23
|
-
puts help_text.split("\n").map { |line| line[/^\s*\|\s\s(.*)$/, 1]}.join("\n")
|
24
|
-
end
|
25
|
-
|
26
|
-
def main(args)
|
27
|
-
if args.size != 1
|
28
|
-
help
|
29
|
-
exit
|
30
|
-
else
|
31
|
-
arg = args.first
|
32
|
-
downcase_arg = arg.downcase
|
33
|
-
if downcase_arg == '--help' || downcase_arg == '-h' || downcase_arg == 'help'
|
34
|
-
help
|
35
|
-
exit
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
applescript = <<-END_OF_APPLESCRIPT
|
40
|
-
try
|
41
|
-
tell application "#{arg}"
|
42
|
-
activate -- If nescessary, starts application. Gives it focus
|
43
|
-
end tell
|
44
|
-
delay 3
|
45
|
-
tell application "System Events"
|
46
|
-
set frontmostName to name of application process 1 whose frontmost is true
|
47
|
-
tell application process frontmostName
|
48
|
-
set uiElems to entire contents
|
49
|
-
end tell
|
50
|
-
end tell
|
51
|
-
(* tell application "System Events"
|
52
|
-
-- Save exit value to a file
|
53
|
-
set the_file to (((path to desktop) as string) & "ui_elements.txt")
|
54
|
-
set nref to open for access file the_file with write permission
|
55
|
-
set eof of the nref to 0
|
56
|
-
set {TID, text item delimiters} to {text item delimiters, ","}
|
57
|
-
set {uiElemsText, text item delimiters} to {uiElems as text, TID}
|
58
|
-
write uiElemsText to nref starting at eof
|
59
|
-
close access nref
|
60
|
-
end tell
|
61
|
-
*)
|
62
|
-
uiElems
|
63
|
-
on error errMsg number errorNumber
|
64
|
-
"Error: " & errMsg & " (#" & (errorNumber as text) & ")"
|
65
|
-
end try
|
66
|
-
END_OF_APPLESCRIPT
|
67
|
-
|
68
|
-
file = Tempfile.new('get_ui_elements')
|
69
|
-
output = begin
|
70
|
-
file.write(applescript)
|
71
|
-
file.close
|
72
|
-
`osascript #{file.path}`
|
73
|
-
ensure
|
74
|
-
file.unlink # Release the temporary script file
|
75
|
-
end
|
76
|
-
if output =~ /^Error/
|
77
|
-
$stderr.puts output.chomp
|
78
|
-
exit 1
|
79
|
-
end
|
80
|
-
puts output.gsub(/,\s+/,"\n")
|
81
|
-
end
|
82
|
-
|
83
|
-
if __FILE__ == $0
|
84
|
-
main(ARGV)
|
85
|
-
end
|
data/lib/gui/version.rb
DELETED