-
Notifications
You must be signed in to change notification settings - Fork 0
/
close_window.rb
63 lines (51 loc) · 1.38 KB
/
close_window.rb
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
require "rautomation"
class CloseWindow
attr_writer :window, :button
# creates an instance variable with the window's name
def window_search(window_name)
# window title with regexp
@window = RAutomation::Window.new(:title => /#{window_name}/i)
end
# does window exists - returns true if yes
def window_exists?
@window.exists?
end
# close window name
def window_close
@window.close
end
# a message
def window_does_not_exist
puts("Window named #{@window.title} does not exist")
end
#is the number of parameters different than 2?
#ARGV is special function that takes parameter from command prompt
def wrong_num_parameters?
(ARGV.size != 1)
end
def wrong_num_parameters_message
puts("Usage: script \"<window_name>\"")
puts("[!] I need window name in order to close it")
end
begin
# new instance
app = CloseWindow.new
# is the number of arguments ok?
if app.wrong_num_parameters? #ARGV.size != 1
app.wrong_num_parameters_message
exit!
end
# first argument has to be the the window name
app.window_search(ARGV[0])
# does the window exists? (if not exit)
if app.window_exists?
app.window_close
else
app.window_does_not_exist
exit!
end
rescue Exception => e
puts e.message
puts e.backtrace.inspect
end
end