Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
osaka.tmproj
osaka*.gem
Gemfile.lock
.DS_Store
*.sublime*
2 changes: 2 additions & 0 deletions lib/osaka.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
require 'osaka/typicalopendialog'
require 'osaka/typicalsavedialog'
require 'osaka/typicalprintdialog'
require 'osaka/typicalfinddialog'
require 'osaka/keynoteprintdialog.rb'

#Specific application
require 'osaka/pages'
Expand Down
2 changes: 1 addition & 1 deletion lib/osaka/defaultssystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(domain)
parse_settings_file(Osaka::CommandRunner.run("defaults read #{domain}"))
end

def parse_settings_file (settings_from_defaults)
def parse_settings_file(settings_from_defaults)
scanner = StringScanner.new (settings_from_defaults)
scanner.scan(/{\n/)
while scanner.scan(/\s+(.*) = (.*);\n/) do
Expand Down
54 changes: 49 additions & 5 deletions lib/osaka/keynote.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,73 @@

module Osaka

class KeynotePrintDialog < TypicalPrintDialog

end

class Keynote < TypicalApplication

def initialize
super "Keynote"
end

def create_print_dialog(location)
KeynotePrintDialog.new(control.name, at.window("Print"))
Osaka::KeynotePrintDialog.new(control.name, at.window("Print"))
end

def select_all_slides
light_table_view
select_all
end

def open (filename)
abolutePathFileName = File.absolute_path(filename)
new_window = do_and_wait_for_new_window {
# Weird that keynote v6 open via osascript is flakey
# was: control.tell("open \"#{abolutePathFileName}\"")
# But now uses the run_command
control.run_command "open #{abolutePathFileName}"
}
control.wait_until_exists(at.window(File.basename(filename)))
control.set_current_window(new_window)
end

def light_table_view
if control.exists?(at.menu_item("Light Table").menu(1).menu_bar_item("View").menu_bar(1))
control.click(at.menu_item("Light Table").menu(1).menu_bar_item("View").menu_bar(1))
end
end

def click_view_menu item
control.click view_menu_bar_item item
end

def view_menu_bar_item(item)
at.menu_item(item).menu(1).menu_bar_item("View").menu_bar(1)
end

def edit_master_slides
click_view_menu "Edit Master Slides"
end

def exit_master_slides
click_view_menu "Exit Master Slides"
end

def exit_master_slides
click_view_menu "Exit Master Slides"
end

def open_print_dialog
control.keystroke("p", :command)
location = at.sheet(1)
control.wait_until_exists(location)
create_dialog(KeynotePrintDialog, location)
end

def print_pdf output_pdf, slides_per_page
dialog = open_print_dialog
dialog.use_page_margins
dialog.slides_per_page slides_per_page
# dialog.save_as_pdf output_pdf
end


end
end
56 changes: 51 additions & 5 deletions lib/osaka/keynoteflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ module CommonFlows
def self.keynote_combine_files(result_file, files_to_merge)
keynote = Osaka::Keynote.new
keynote.activate
keynote.close_template_chooser_if_any
keynote.raise_error_on_open_standard_windows("All Keynote windows must be closed before running this flow")

files_to_merge = [files_to_merge].flatten
keynote.open(files_to_merge.shift)
keynote.light_table_view
keynote.select_all_slides
keynote.save_as(result_file)


Expand All @@ -17,12 +18,12 @@ def self.keynote_combine_files(result_file, files_to_merge)
combine_keynote.open(file)
combine_keynote.select_all_slides
combine_keynote.copy
combine_keynote.close
keynote.select_all_slides
keynote.paste
combine_keynote.close
keynote.save
puts "Finished " + file
}

keynote.save
keynote.close
keynote.quit
end
Expand All @@ -33,5 +34,50 @@ def self.keynote_combine_files_from_directory_sorted(result_file, directory = ".
files_to_open = files_in_directory.collect { |f| File.join(directory, f)}
keynote_combine_files(result_file, files_to_open.sort)
end


def self.keynote_yield_for_each_file(files)
keynote = Osaka::Keynote.new
keynote.activate
keynote.close_template_chooser_if_any
keynote.raise_error_on_open_standard_windows("All Keynote windows must be closed before running this flow")
files = [files].flatten
files.each { |file|
keynote = Osaka::Keynote.new
keynote.open(file)
yield keynote
keynote.close
}
keynote.quit
end

def self.keynote_combine_files_from_list(result_file, directory, keynote_files)
files_with_path = keynote_files.collect { |f| File.join(directory, f)}
missing_files = ""
files_with_path.each { |f|
if !File.exist?(f)
missing_files += "\n" + f
end
}

if missing_files.empty?
keynote_combine_files(result_file, files_with_path)
else
puts "These files do not exist: " + missing_files
end

end

def self.start_keynote
keynote = Osaka::Keynote.new
keynote.activate
keynote.close_template_chooser_if_any
keynote.raise_error_on_open_standard_windows("All Keynote windows must be closed before running this flow")
keynote
end

def self.search_and_replace_presentation_text(keynote, find, replacement)
keynote.find_replace_all(find, replacement)
keynote.save
end

end
48 changes: 48 additions & 0 deletions lib/osaka/keynoteprintdialog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Osaka

class KeynotePrintDialog < TypicalPrintDialog
attr_accessor :control

def initialize(application_name, own_location)
@control = Osaka::RemoteControl.new(application_name, own_location)
end

def margins(value)
element = at.checkbox("Use page margins").group(3)
control.set_checkbox(element, value)
end

def backgrounds(value)
element = at.checkbox("Print slide backgrounds")
control.set_checkbox(element, value)
end

def animations(value)
element = at.checkbox("Print each stage of builds")
control.set_checkbox(element, value)
end

def save_pdf_course_notes(filename = nil)
open_save_as_pdf_dialog
if filename
control.set("value", at.text_field(1).sheet(1) , filename)
sleep 1
end
save_pdf
end

def open_save_as_pdf_dialog
control.keystroke("d", :command)
sleep 1
end

def save_pdf
control.click(at.button("Save").sheet(1))
end

def cancel
control.click(at.button("Cancel"))
end
end
end

8 changes: 8 additions & 0 deletions lib/osaka/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def menu_bar(name)
create_location_with_added_name("menu bar", name)
end

def combo_box(name)
create_location_with_added_name("combo box", name)
end

def has_menu_bar?
has_element?("menu bar")
end
Expand All @@ -86,6 +90,10 @@ def dialog(name)
create_location_with_added_name("dialog", name)
end

def floating_window(name)
create_location_with_added_name("floating window", name)
end

def checkbox(name)
create_location_with_added_name("checkbox", name)
end
Expand Down
17 changes: 12 additions & 5 deletions lib/osaka/remotecontrol.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

require 'timeout'

module Osaka
Expand Down Expand Up @@ -149,7 +149,15 @@ def click_menu_bar(menu_item, menu_name)
menu_bar_location = at.menu_bar_item(menu_name).menu_bar(1)
click!(menu_item + at.menu(1) + menu_bar_location)
end


def set_checkbox(element, value)
its_value = get!("value", element).to_i
value = value ? 1 : 0
return if its_value == value
click(element)
sleep 1
end

def set!(element, location, value)
encoded_value = (value.class == String) ? "\"#{value}\"" : value.to_s
check_output( system_event!("set #{element}#{construct_prefixed_location(location)} to #{encoded_value}"), "set")
Expand Down Expand Up @@ -252,9 +260,8 @@ def mac_version_string
@mac_version_string
end


def convert_mac_version_string_to_symbol(version_string)

def run_command command
Osaka::CommandRunner.run command
end

end
Expand Down
33 changes: 29 additions & 4 deletions lib/osaka/typicalapplication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_info
ApplicationInfo.new(script_info)
end

def open (filename)
def open(filename)
abolutePathFileName = File.absolute_path(filename)
new_window = do_and_wait_for_new_window {
control.tell("open \"#{abolutePathFileName}\"")
Expand Down Expand Up @@ -122,7 +122,15 @@ def duplicate_and_close_original
def save
control.keystroke("s", :command)
end


def find_replace_all text, replacement
control.keystroke("f", :command)
location = at.window("Find & Replace")
control.wait_until_exists(location)
dialog = create_dialog(TypicalFindDialog, location)
dialog.find_replace_all text, replacement
end

def save_pops_up_dialog?
control.exists?(at.menu_item("Save…").menu(1).menu_bar_item("File").menu_bar(1))
end
Expand Down Expand Up @@ -185,9 +193,9 @@ def select_all
control.keystroke("a", :command)
end

def print_dialog
def print_dialog dialog_class = TypicalPrintDialog
control.keystroke("p", :command).wait_until_exists(at.sheet(1))
create_dialog(TypicalPrintDialog, at.sheet(1))
create_dialog(dialog_class, at.sheet(1))
end

def create_dialog(dialog_class, location)
Expand All @@ -200,8 +208,25 @@ def select_file_from_open_dialog(filename, dialog_location)
dialog.select_file(File.basename(filename))
end

def template_chooser_window?
focus
current_window_name = control.current_window_name
current_window_name == "Choose a Theme" ||
current_window_name == "Choose a Template" ||
current_window_name == "Template Chooser" ? true : false
end

def close_template_chooser_if_any
if template_chooser_window?
window = at.window(control.current_window_name)
close
control.wait_until_not_exists!(window)
end
end

def raise_error_on_open_standard_windows(error_message)
raise Osaka::ApplicationWindowsMustBeClosed, error_message if ! control.standard_window_list.empty?
end
end
end

40 changes: 40 additions & 0 deletions lib/osaka/typicalfinddialog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# encoding: utf-8
module Osaka

class TypicalFindDialog

def initialize(application_name, own_location)
@control = Osaka::RemoteControl.new(application_name, own_location)
end

def find_replace_all string, replacement
string_to_find string
string_replacement replacement
wait_for_replace_all_button?
click_replace_all
close
end

def string_to_find string
@control.set("value", at.text_field(1), string)
end

def string_replacement replacement
@control.set("value", at.text_field(2) , replacement)
end

def wait_for_replace_all_button?
@control.wait_until_exists(at.button("Replace All"))
end

def click_replace_all
@control.click(at.button("Replace All"))
end

def close
@control.keystroke('w', :command)
end

end

end
Loading