osaka 0.2.3 → 0.3.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.
- data/lib/osaka/applicationwrapper.rb +64 -20
- data/lib/osaka/applicationwrapperexpectations.rb +4 -0
- data/lib/osaka/calculator.rb +5 -5
- data/lib/osaka/keynote.rb +9 -0
- data/lib/osaka/keynoteflow.rb +29 -0
- data/lib/osaka/location.rb +132 -0
- data/lib/osaka/mailmergeflow.rb +19 -0
- data/lib/osaka/pages.rb +10 -7
- data/lib/osaka/scriptrunner.rb +18 -3
- data/lib/osaka/textedit.rb +2 -2
- data/lib/osaka/typicalapplication.rb +80 -27
- data/lib/osaka/version.rb +1 -1
- data/lib/osaka.rb +3 -0
- data/spec/applicationwrapper_spec.rb +76 -39
- data/spec/assets/01_first_slides.key +0 -0
- data/spec/assets/02_second_slides.key +0 -0
- data/spec/assets/03_third_slides.key +0 -0
- data/spec/assets/mail_merge_data.numbers +0 -0
- data/spec/assets/mail_merge_template.pages +0 -0
- data/spec/calculator_spec.rb +6 -6
- data/spec/integration_calculator_spec.rb +0 -1
- data/spec/integration_keynote_spec.rb +29 -0
- data/spec/integration_pages_numbers_mail_merge_spec.rb +17 -0
- data/spec/integration_textedit_spec.rb +7 -3
- data/spec/keynote_flows_spec.rb +62 -0
- data/spec/keynote_spec.rb +21 -1
- data/spec/location_spec.rb +53 -0
- data/spec/mailmergeflow_spec.rb +40 -0
- data/spec/pages_spec.rb +13 -13
- data/spec/scriptrunner_spec.rb +9 -0
- data/spec/textedit_spec.rb +3 -3
- data/spec/typicalapplication_spec.rb +94 -29
- metadata +15 -2
@@ -32,28 +32,33 @@ module Osaka
|
|
32
32
|
|
33
33
|
class CheckAction
|
34
34
|
def execute(wrapper, condition, *args, &block)
|
35
|
-
wrapper.system_event!("#{condition.as_script(*args)};").strip == "true"
|
35
|
+
wrapper.system_event!("#{condition.as_script(wrapper, *args)};").strip == "true"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
class ExistsCondition
|
40
|
-
def as_script(element_to_check)
|
41
|
-
"exists #{element_to_check}"
|
40
|
+
def as_script(wrapper, element_to_check)
|
41
|
+
"exists #{wrapper.construct_location(element_to_check)}"
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
class Not_existsCondition
|
46
|
-
def as_script(element_to_check)
|
47
|
-
"not exists #{element_to_check}"
|
46
|
+
def as_script(wrapper, element_to_check)
|
47
|
+
"not exists #{wrapper.construct_location(element_to_check)}"
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
class ApplicationWrapper
|
52
52
|
|
53
|
-
|
53
|
+
attr_reader :name
|
54
54
|
|
55
55
|
def initialize(name)
|
56
56
|
@name = name
|
57
|
+
@window = Location.new("")
|
58
|
+
end
|
59
|
+
|
60
|
+
def ==(obj)
|
61
|
+
@name == obj.name && current_window_name == obj.current_window_name
|
57
62
|
end
|
58
63
|
|
59
64
|
def tell(command)
|
@@ -64,6 +69,10 @@ module Osaka
|
|
64
69
|
ScriptRunner::execute("tell application \"System Events\"; tell process \"#{@name}\"; #{event}; end tell; end tell")
|
65
70
|
end
|
66
71
|
|
72
|
+
def running?
|
73
|
+
ScriptRunner::execute("tell application \"System Events\"; (name of processes) contains \"#{@name}\"; end tell").strip == "true"
|
74
|
+
end
|
75
|
+
|
67
76
|
def print_warning(action, message)
|
68
77
|
puts "Osaka WARNING while doing #{action}: #{message}"
|
69
78
|
end
|
@@ -122,7 +131,7 @@ module Osaka
|
|
122
131
|
|
123
132
|
def click!(element)
|
124
133
|
# Click seems to often output stuff, but it doesn't have much meaning so we ignore it.
|
125
|
-
system_event!("click #{element}")
|
134
|
+
system_event!("click #{construct_location(element)}")
|
126
135
|
self
|
127
136
|
end
|
128
137
|
|
@@ -130,30 +139,46 @@ module Osaka
|
|
130
139
|
activate
|
131
140
|
click!(element)
|
132
141
|
end
|
142
|
+
|
143
|
+
def click_menu_bar(menu_item, menu_name)
|
144
|
+
activate
|
145
|
+
menu_bar_location = at.menu_bar_item(menu_name).menu_bar(1)
|
146
|
+
click!(menu_item + at.menu(1) + menu_bar_location)
|
147
|
+
end
|
133
148
|
|
134
149
|
def set!(element, location, value)
|
135
150
|
encoded_value = (value.class == String) ? "\"#{value}\"" : value.to_s
|
136
|
-
check_output( system_event!("set #{element}
|
151
|
+
check_output( system_event!("set #{element}#{construct_prefixed_location(location)} to #{encoded_value}"), "set")
|
137
152
|
end
|
138
153
|
|
139
154
|
def focus
|
140
155
|
current_windows = window_list
|
141
|
-
|
142
|
-
|
156
|
+
currently_active_window = current_windows[0]
|
157
|
+
currently_active_window ||= ""
|
158
|
+
|
159
|
+
if current_window_invalid?(current_windows)
|
160
|
+
@window = at.window(currently_active_window) unless currently_active_window.nil?
|
161
|
+
end
|
162
|
+
|
163
|
+
set!("value", "attribute \"AXMain\"", true) unless currently_active_window == current_window_name
|
143
164
|
end
|
144
165
|
|
145
|
-
def
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
166
|
+
def form_location_with_window(location)
|
167
|
+
new_location = Location.new(location)
|
168
|
+
new_location += @window unless new_location.has_top_level_element?
|
169
|
+
new_location
|
170
|
+
end
|
171
|
+
|
172
|
+
def construct_location(location)
|
173
|
+
form_location_with_window(location).to_s
|
174
|
+
end
|
175
|
+
|
176
|
+
def construct_prefixed_location(location)
|
177
|
+
form_location_with_window(location).as_prefixed_location
|
153
178
|
end
|
154
179
|
|
155
180
|
def get!(element, location = "")
|
156
|
-
system_event!("get #{element}#{
|
181
|
+
system_event!("get #{element}#{construct_prefixed_location(location)}").strip
|
157
182
|
end
|
158
183
|
|
159
184
|
def get_app!(element)
|
@@ -171,5 +196,24 @@ module Osaka
|
|
171
196
|
window[7...window =~ / of application process/].strip
|
172
197
|
}
|
173
198
|
end
|
199
|
+
|
200
|
+
def set_current_window(window_name)
|
201
|
+
@window = at.window(window_name)
|
202
|
+
end
|
203
|
+
|
204
|
+
def current_window_name
|
205
|
+
matchdata = @window.to_s.match(/^window "(.*)"/)
|
206
|
+
return "" if matchdata.nil? || matchdata[1].nil?
|
207
|
+
matchdata[1]
|
208
|
+
end
|
209
|
+
|
210
|
+
def current_window_location
|
211
|
+
@window
|
212
|
+
end
|
213
|
+
|
214
|
+
def current_window_invalid?(window_list)
|
215
|
+
@window.to_s.empty? || window_list.index(current_window_name).nil?
|
216
|
+
end
|
217
|
+
|
174
218
|
end
|
175
219
|
end
|
@@ -37,6 +37,10 @@ module Osaka
|
|
37
37
|
@wrapper.should_receive(:click).with(location).and_return(@wrapper)
|
38
38
|
end
|
39
39
|
|
40
|
+
def expect_click_menu_bar(menu_item, menu_name)
|
41
|
+
@wrapper.should_receive(:click_menu_bar).with(menu_item, menu_name).and_return(@wrapper)
|
42
|
+
end
|
43
|
+
|
40
44
|
def expect_tell(do_this)
|
41
45
|
@wrapper.should_receive(:tell).with(do_this)
|
42
46
|
end
|
data/lib/osaka/calculator.rb
CHANGED
@@ -6,18 +6,19 @@ module Osaka
|
|
6
6
|
def initialize
|
7
7
|
@name = "Calculator"
|
8
8
|
@wrapper = ApplicationWrapper.new("Calculator")
|
9
|
+
@wrapper.set_current_window(@name)
|
9
10
|
end
|
10
11
|
|
11
12
|
def activate
|
12
13
|
super
|
13
|
-
if (@wrapper.
|
14
|
+
if (@wrapper.current_window_name.empty?)
|
14
15
|
wait_for_new_window([])
|
15
|
-
@wrapper.
|
16
|
+
@wrapper.set_current_window(@wrapper.window_list[0])
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
def click(key)
|
20
|
-
@wrapper.click!(
|
21
|
+
@wrapper.click!(at.button(key).group(2))
|
21
22
|
end
|
22
23
|
|
23
24
|
def key(k)
|
@@ -25,8 +26,7 @@ module Osaka
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def result
|
28
|
-
@wrapper.get!('value',
|
29
|
+
@wrapper.get!('value', at.static_text(1).group(1))
|
29
30
|
end
|
30
|
-
|
31
31
|
end
|
32
32
|
end
|
data/lib/osaka/keynote.rb
CHANGED
@@ -14,5 +14,14 @@ module Osaka
|
|
14
14
|
def create_print_dialog(location)
|
15
15
|
KeynotePrintDialog.new(location, @wrapper)
|
16
16
|
end
|
17
|
+
|
18
|
+
def select_all_slides
|
19
|
+
if @wrapper.check!.exists(at.button("Slides").group(1).outline(1).scroll_area(2).splitter_group(1).splitter_group(1))
|
20
|
+
@wrapper.click(at.button("Slides").group(1).outline(1).scroll_area(2).splitter_group(1).splitter_group(1))
|
21
|
+
else
|
22
|
+
@wrapper.click(at.button("Slides").group(1).outline(1).scroll_area(1).splitter_group(1).splitter_group(1))
|
23
|
+
end
|
24
|
+
select_all
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module CommonFlows
|
3
|
+
def self.keynote_combine_files(result_file, files_to_merge)
|
4
|
+
keynote = Osaka::Keynote.new
|
5
|
+
files_to_merge = [files_to_merge].flatten
|
6
|
+
keynote.open(files_to_merge.shift)
|
7
|
+
keynote.save_as(result_file)
|
8
|
+
|
9
|
+
files_to_merge.each { |file|
|
10
|
+
combine_keynote = Osaka::Keynote.new
|
11
|
+
combine_keynote.open(file)
|
12
|
+
combine_keynote.select_all_slides
|
13
|
+
combine_keynote.copy
|
14
|
+
keynote.select_all_slides
|
15
|
+
keynote.paste
|
16
|
+
combine_keynote.close
|
17
|
+
}
|
18
|
+
|
19
|
+
keynote.save
|
20
|
+
keynote.quit
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.keynote_combine_files_from_directory_sorted(result_file, directory = ".", pattern = /^.*\.key$/)
|
24
|
+
files_in_directory = Dir.new(directory).entries
|
25
|
+
files_in_directory.select! { |f| f =~ pattern }
|
26
|
+
files_to_open = files_in_directory.collect { |f| File.join(directory, f)}
|
27
|
+
keynote_combine_files(result_file, files_to_open.sort)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
|
2
|
+
module Osaka
|
3
|
+
class Location
|
4
|
+
|
5
|
+
def initialize(location_name)
|
6
|
+
@location_name = location_name.to_s
|
7
|
+
validate
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate
|
11
|
+
raise(Osaka::InvalidLocation, "Invalid location: #{to_s}") if as_prefixed_location.scan(" of window").length > 1
|
12
|
+
end
|
13
|
+
|
14
|
+
def+(other_location)
|
15
|
+
return Location.new(self) if other_location.to_s.empty?
|
16
|
+
return Location.new(other_location) if to_s.empty?
|
17
|
+
Location.new(to_s + " of " + other_location.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
@location_name
|
22
|
+
end
|
23
|
+
|
24
|
+
def as_prefixed_location
|
25
|
+
return "" if to_s.empty?
|
26
|
+
" of " + to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_top_level_element?
|
30
|
+
has_window? || has_menu_bar?
|
31
|
+
end
|
32
|
+
|
33
|
+
def button(name)
|
34
|
+
create_location_with_added_name("button", name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def group(name)
|
38
|
+
create_location_with_added_name("group", name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def window(name)
|
42
|
+
create_location_with_added_name("window", name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def has_window?
|
46
|
+
has_element?("window")
|
47
|
+
end
|
48
|
+
|
49
|
+
def static_text(name)
|
50
|
+
create_location_with_added_name("static text", name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def menu_button(name)
|
54
|
+
create_location_with_added_name("menu button", name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def menu(name)
|
58
|
+
create_location_with_added_name("menu", name)
|
59
|
+
end
|
60
|
+
|
61
|
+
def menu_item(name)
|
62
|
+
create_location_with_added_name("menu item", name)
|
63
|
+
end
|
64
|
+
|
65
|
+
def menu_bar(name)
|
66
|
+
create_location_with_added_name("menu bar", name)
|
67
|
+
end
|
68
|
+
|
69
|
+
def has_menu_bar?
|
70
|
+
has_element?("menu bar")
|
71
|
+
end
|
72
|
+
|
73
|
+
def menu_bar_item(name)
|
74
|
+
create_location_with_added_name("menu bar item", name)
|
75
|
+
end
|
76
|
+
|
77
|
+
def dialog(name)
|
78
|
+
create_location_with_added_name("dialog", name)
|
79
|
+
end
|
80
|
+
|
81
|
+
def checkbox(name)
|
82
|
+
create_location_with_added_name("checkbox", name)
|
83
|
+
end
|
84
|
+
|
85
|
+
def sheet(name)
|
86
|
+
create_location_with_added_name("sheet", name)
|
87
|
+
end
|
88
|
+
|
89
|
+
def text_field(name)
|
90
|
+
create_location_with_added_name("text field", name)
|
91
|
+
end
|
92
|
+
|
93
|
+
def pop_up_button(name)
|
94
|
+
create_location_with_added_name("pop up button", name)
|
95
|
+
end
|
96
|
+
|
97
|
+
def splitter_group(name)
|
98
|
+
create_location_with_added_name("splitter group", name)
|
99
|
+
end
|
100
|
+
|
101
|
+
def scroll_area(name)
|
102
|
+
create_location_with_added_name("scroll area", name)
|
103
|
+
end
|
104
|
+
|
105
|
+
def outline(name)
|
106
|
+
create_location_with_added_name("outline", name)
|
107
|
+
end
|
108
|
+
|
109
|
+
def to_location_string(name)
|
110
|
+
return name.to_s if name.kind_of? Integer
|
111
|
+
'"' + name.to_s + '"'
|
112
|
+
end
|
113
|
+
|
114
|
+
def create_location_with_added_name(element, name)
|
115
|
+
self + Location.new(element + " " + to_location_string(name))
|
116
|
+
end
|
117
|
+
|
118
|
+
def has_element?(name)
|
119
|
+
as_prefixed_location.scan(" of #{name}").length >= 1
|
120
|
+
end
|
121
|
+
|
122
|
+
def ==(obj)
|
123
|
+
@location_name == obj.to_s
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
def at
|
131
|
+
Osaka::Location.new ""
|
132
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module CommonFlows
|
3
|
+
|
4
|
+
def self.number_and_pages_mail_merge(numbers_file, pages_file, output_file)
|
5
|
+
numbers = Osaka::Numbers.new
|
6
|
+
pages = Osaka::Pages.new
|
7
|
+
|
8
|
+
numbers.open(numbers_file)
|
9
|
+
yield numbers if block_given?
|
10
|
+
numbers.save
|
11
|
+
|
12
|
+
pages.open(pages_file)
|
13
|
+
pages.mail_merge_to_pdf(output_file)
|
14
|
+
|
15
|
+
numbers.quit(:dont_save)
|
16
|
+
pages.quit(:dont_save)
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/osaka/pages.rb
CHANGED
@@ -9,7 +9,7 @@ module Osaka
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def merge
|
12
|
-
@wrapper.click!(
|
12
|
+
@wrapper.click!(at.button("Merge").sheet(1))
|
13
13
|
print_dialog_location = 'window "Print"'
|
14
14
|
@wrapper.wait_until!.exists("menu button \"PDF\" of #{print_dialog_location}")
|
15
15
|
TypicalPrintDialog.new(print_dialog_location, @wrapper)
|
@@ -25,9 +25,9 @@ module Osaka
|
|
25
25
|
|
26
26
|
private
|
27
27
|
def set_merge_to_document_printer(value)
|
28
|
-
@wrapper.click(
|
29
|
-
@wrapper.wait_until!.exists(
|
30
|
-
@wrapper.click!(
|
28
|
+
@wrapper.click(at.pop_up_button(2).sheet(1))
|
29
|
+
@wrapper.wait_until!.exists(at.menu_item(value).menu(1).pop_up_button(2).sheet(1))
|
30
|
+
@wrapper.click!(at.menu_item(value).menu(1).pop_up_button(2).sheet(1))
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -38,9 +38,12 @@ module Osaka
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def mail_merge
|
41
|
-
@wrapper.
|
42
|
-
@wrapper.
|
43
|
-
|
41
|
+
@wrapper.click_menu_bar(at.menu_item(20), "Edit")
|
42
|
+
# @wrapper.click!(at.menu_bar_item("Edit").menu_bar(1))
|
43
|
+
# @wrapper.wait_until.exists(at.menu(1).menu_bar_item("Edit").menu_bar(1))
|
44
|
+
# @wrapper.click!(at.menu_item(20).menu(1).menu_bar_item("Edit").menu_bar(1))
|
45
|
+
@wrapper.wait_until.exists(at.button("Merge").sheet(1))
|
46
|
+
PagesMailMergeDialog.new(at.sheet(1), @wrapper)
|
44
47
|
end
|
45
48
|
|
46
49
|
def mail_merge_to_pdf(filename)
|
data/lib/osaka/scriptrunner.rb
CHANGED
@@ -11,8 +11,9 @@ module Osaka
|
|
11
11
|
|
12
12
|
@@debug_info_enabled = false
|
13
13
|
|
14
|
-
def self.enable_debug_prints
|
14
|
+
def self.enable_debug_prints(debug_info_format = :plain_text)
|
15
15
|
@@debug_info_enabled = true
|
16
|
+
@@debug_info_format = debug_info_format
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.disable_debug_prints
|
@@ -29,7 +30,16 @@ module Osaka
|
|
29
30
|
script_commands.each { |l|
|
30
31
|
escaped_commands += " -e \"#{l.strip}\""
|
31
32
|
}
|
32
|
-
|
33
|
+
if (debug_prints?)
|
34
|
+
if (@@debug_info_format == :plain_text)
|
35
|
+
debug_output = "Executing: osascript#{escaped_commands}"
|
36
|
+
elsif (@@debug_info_format == :short_html)
|
37
|
+
debug_output = applescript
|
38
|
+
debug_output += "<br>"
|
39
|
+
end
|
40
|
+
puts debug_output
|
41
|
+
end
|
42
|
+
|
33
43
|
|
34
44
|
output = ""
|
35
45
|
begin
|
@@ -38,7 +48,12 @@ module Osaka
|
|
38
48
|
raise(Osaka::ScriptRunnerError, "Error received while executing: #{applescript}")
|
39
49
|
end
|
40
50
|
if (!output.empty? && debug_prints?)
|
41
|
-
|
51
|
+
if (@@debug_info_format == :plain_text)
|
52
|
+
debug_output = "Output was: #{output}"
|
53
|
+
elsif (@@debug_info_format == :short_html)
|
54
|
+
debug_output = "Output: <b>#{output}</b><br>"
|
55
|
+
end
|
56
|
+
puts debug_output
|
42
57
|
end
|
43
58
|
output
|
44
59
|
end
|
data/lib/osaka/textedit.rb
CHANGED
@@ -10,9 +10,9 @@ module Osaka
|
|
10
10
|
|
11
11
|
def activate
|
12
12
|
super
|
13
|
-
if (@wrapper.
|
13
|
+
if (@wrapper.current_window_name.empty?)
|
14
14
|
wait_for_new_window([])
|
15
|
-
@wrapper.
|
15
|
+
@wrapper.set_current_window(@wrapper.window_list[0])
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -4,23 +4,24 @@ module Osaka
|
|
4
4
|
class TypicalSaveDialog
|
5
5
|
attr_accessor :wrapper
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
-
@wrapper = wrapper
|
7
|
+
def initialize(self_location, wrapper)
|
8
|
+
@self_location = self_location
|
9
|
+
@wrapper = wrapper.clone
|
10
|
+
@wrapper.set_current_window("") if self_location.has_top_level_element?
|
10
11
|
end
|
11
12
|
|
12
13
|
def set_filename(filename)
|
13
|
-
@wrapper.set("value",
|
14
|
+
@wrapper.set("value", at.text_field(1) + @self_location, filename)
|
14
15
|
end
|
15
16
|
|
16
17
|
def set_folder(pathname)
|
17
|
-
@wrapper.keystroke("g", [ :command, :shift ]).wait_until.exists(
|
18
|
-
@wrapper.set("value",
|
19
|
-
@wrapper.click(
|
18
|
+
@wrapper.keystroke("g", [ :command, :shift ]).wait_until.exists(at.sheet(1) + @self_location)
|
19
|
+
@wrapper.set("value", at.text_field(1).sheet(1) + @self_location, pathname)
|
20
|
+
@wrapper.click(at.button("Go").sheet(1) + @self_location).wait_until.not_exists(at.sheet(1) + @self_location)
|
20
21
|
end
|
21
22
|
|
22
23
|
def click_save
|
23
|
-
@wrapper.click(
|
24
|
+
@wrapper.click(at.button("Save") + @self_location).wait_until.not_exists(@self_location)
|
24
25
|
end
|
25
26
|
|
26
27
|
def save(filename)
|
@@ -34,8 +35,8 @@ module Osaka
|
|
34
35
|
class TypicalPrintDialog
|
35
36
|
attr_accessor :wrapper
|
36
37
|
|
37
|
-
def initialize(
|
38
|
-
@
|
38
|
+
def initialize(parent, wrapper)
|
39
|
+
@parent = parent
|
39
40
|
@wrapper = wrapper
|
40
41
|
end
|
41
42
|
|
@@ -44,15 +45,15 @@ module Osaka
|
|
44
45
|
end
|
45
46
|
|
46
47
|
def save_as_pdf(filename)
|
47
|
-
@wrapper.click!("
|
48
|
-
@wrapper.click!(
|
49
|
-
save_dialog = create_save_dialog(
|
48
|
+
@wrapper.click!(at.menu_button("PDF") + @parent).wait_until!.exists(at.menu(1).menu_button("PDF") + @parent)
|
49
|
+
@wrapper.click!(at.menu_item(2).menu(1).menu_button("PDF") + @parent).wait_until!.exists('window "Save"')
|
50
|
+
save_dialog = create_save_dialog(at.window("Save"), @wrapper)
|
50
51
|
save_dialog.save(filename)
|
51
52
|
|
52
|
-
@wrapper.until!.not_exists(@
|
53
|
+
@wrapper.until!.not_exists(@parent) {
|
53
54
|
# Weird, but sometimes the dialog "hangs around" and clicking this checkbox will make it go away.
|
54
55
|
# Anyone who knows a better solution, please let me know!
|
55
|
-
@wrapper.click!(
|
56
|
+
@wrapper.click!(at.checkbox(1).window("Print"))
|
56
57
|
}
|
57
58
|
end
|
58
59
|
end
|
@@ -84,22 +85,36 @@ module Osaka
|
|
84
85
|
def open (filename)
|
85
86
|
abolutePathFileName = File.absolute_path(filename)
|
86
87
|
@wrapper.tell("open \"#{abolutePathFileName}\"")
|
87
|
-
@wrapper.
|
88
|
+
@wrapper.set_current_window(File.basename(filename))
|
88
89
|
end
|
89
90
|
|
90
91
|
def wait_for_window_and_dialogs_to_close(option)
|
91
92
|
if (option != :user_chose)
|
92
|
-
@wrapper.until!.not_exists(
|
93
|
-
|
94
|
-
@wrapper.click!("button 2 of sheet 1 of window \"#{wrapper.window}\"")
|
95
|
-
end
|
93
|
+
@wrapper.until!.not_exists(@wrapper.current_window_location) {
|
94
|
+
close_dialog_sheet_with_dont_save
|
96
95
|
}
|
97
96
|
end
|
98
97
|
end
|
99
|
-
|
98
|
+
|
99
|
+
def wait_for_application_to_quit(option)
|
100
|
+
if (option != :user_chose)
|
101
|
+
while @wrapper.running?
|
102
|
+
close_dialog_sheet_with_dont_save
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def close_dialog_sheet_with_dont_save
|
108
|
+
if (@wrapper.check!.exists(at.sheet(1)))
|
109
|
+
@wrapper.click!(at.button(2).sheet(1))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
100
113
|
def quit(option = :user_chose)
|
101
|
-
@wrapper.
|
102
|
-
|
114
|
+
if @wrapper.running?
|
115
|
+
@wrapper.quit
|
116
|
+
wait_for_application_to_quit(option)
|
117
|
+
end
|
103
118
|
end
|
104
119
|
|
105
120
|
def wait_for_new_window(original_window_list)
|
@@ -113,7 +128,7 @@ module Osaka
|
|
113
128
|
def new_document
|
114
129
|
window_list = @wrapper.window_list
|
115
130
|
@wrapper.keystroke("n", :command)
|
116
|
-
@wrapper.
|
131
|
+
@wrapper.set_current_window(wait_for_new_window(window_list))
|
117
132
|
@wrapper.focus
|
118
133
|
end
|
119
134
|
|
@@ -121,6 +136,17 @@ module Osaka
|
|
121
136
|
@wrapper.keystroke("s", :command)
|
122
137
|
end
|
123
138
|
|
139
|
+
def save_dialog
|
140
|
+
@wrapper.keystroke("s", [:command, :shift]).wait_until.exists(at.sheet(1))
|
141
|
+
create_save_dialog(at.sheet(1))
|
142
|
+
end
|
143
|
+
|
144
|
+
def save_as(filename)
|
145
|
+
dialog = save_dialog
|
146
|
+
dialog.save(filename)
|
147
|
+
@wrapper.set_current_window(File.basename(filename))
|
148
|
+
end
|
149
|
+
|
124
150
|
def close(option = :user_chose)
|
125
151
|
@wrapper.keystroke("w", :command)
|
126
152
|
wait_for_window_and_dialogs_to_close(option)
|
@@ -129,15 +155,42 @@ module Osaka
|
|
129
155
|
def activate
|
130
156
|
@wrapper.activate
|
131
157
|
end
|
158
|
+
|
159
|
+
def focus
|
160
|
+
@wrapper.focus
|
161
|
+
end
|
162
|
+
|
163
|
+
def running?
|
164
|
+
@wrapper.running?
|
165
|
+
end
|
132
166
|
|
167
|
+
def copy
|
168
|
+
@wrapper.keystroke("c", :command)
|
169
|
+
end
|
170
|
+
|
171
|
+
def paste
|
172
|
+
@wrapper.keystroke("v", :command)
|
173
|
+
end
|
174
|
+
|
175
|
+
def cut
|
176
|
+
@wrapper.keystroke("x", :command)
|
177
|
+
end
|
178
|
+
|
179
|
+
def select_all
|
180
|
+
@wrapper.keystroke("a", :command)
|
181
|
+
end
|
182
|
+
|
133
183
|
def create_print_dialog(location)
|
134
184
|
TypicalPrintDialog.new(location, @wrapper)
|
135
185
|
end
|
186
|
+
|
187
|
+
def create_save_dialog(location)
|
188
|
+
TypicalSaveDialog.new(location, @wrapper)
|
189
|
+
end
|
136
190
|
|
137
191
|
def print_dialog
|
138
|
-
|
139
|
-
|
140
|
-
create_print_dialog(location)
|
192
|
+
@wrapper.keystroke("p", :command).wait_until.exists(at.sheet(1))
|
193
|
+
create_print_dialog(at.sheet(1))
|
141
194
|
end
|
142
195
|
|
143
196
|
end
|
data/lib/osaka/version.rb
CHANGED
data/lib/osaka.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'osaka/scriptrunner'
|
3
|
+
require 'osaka/location'
|
3
4
|
require 'osaka/applicationwrapper'
|
4
5
|
require 'osaka/applicationwrapperexpectations'
|
5
6
|
require 'osaka/typicalapplication'
|
@@ -8,4 +9,6 @@ require 'osaka/numbers'
|
|
8
9
|
require 'osaka/keynote'
|
9
10
|
require 'osaka/calculator'
|
10
11
|
require 'osaka/textedit'
|
12
|
+
require 'osaka/mailmergeflow'
|
13
|
+
require 'osaka/keynoteflow'
|
11
14
|
|