gui_inspect 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d210dc0561a40901ccc1cacc1a2e0a5231db32279367ba9a06807408048b6e5c
4
- data.tar.gz: a11f2537a086e83eedb739ea699454660386e909f70adeae39bd9dfd558dd34a
3
+ metadata.gz: 5601b05cdf05d0510c1c6a1d6585ec39da2aaa948d312b7e891feb9d0dd0fa21
4
+ data.tar.gz: c12b5c2e9d8af0c0369d2a81653efdf77006ea57ee273e765777ef5093e85a56
5
5
  SHA512:
6
- metadata.gz: eb40ab8bbe9e5bf4a1f2e6834e837513b4c266e7b388c834f7346bbeef03b61ff344acb1f8af61d8da37df56649d817424564001a8d9511ef5fccc5d79ec08a6
7
- data.tar.gz: fa34428280a5059b3af637649ea915eea8b833a6e4b0730c5dfdb0f994955129b9d3bda7c5b1890d2f758d1d7cd813149a7bc18a360c8da09826f14d99cb5e59
6
+ metadata.gz: 9fc36cd368f5f0a524d633065985a892bcb2ce952c69286d4970ea3160ed1b8a99426a4dec3b02b4feef07311ff8cc9c32953454b15fa63b462a1102d55cd3fe
7
+ data.tar.gz: afc66822523031ca85c81ec919929e777c9e0164bcb360fb7a19c4976634779e78443d378836c88fe88c95707a34f485dd7e6a15c7b57789b952eb74f0d4b135
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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GUIInspect
4
+ VERSION = "0.2.0"
5
+
6
+ def self.version
7
+ VERSION
8
+ end
9
+ end
@@ -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.0
4
+ version: 0.2.0
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
- - get_ui_elements
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/get_ui_elements
26
- - lib/gui.rb
27
- - lib/gui/version.rb
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
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gui
4
- VERSION = "0.1.0"
5
- end
data/lib/gui.rb DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "gui/version"
4
-
5
- module Gui
6
- class Error < StandardError; end
7
- # Your code goes here...
8
- end