class Dutchman::GhostWriter::AppleScript::Application
Attributes
command[R]
container[R]
name[R]
Public Class Methods
new(container,name)
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 6 def initialize(container,name) @container = container @name = name end
Public Instance Methods
applescript()
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 33 def applescript tell_application_command end
execute()
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 37 def execute container.execute(applescript) end
keystroke(key_name)
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 23 def keystroke(key_name) command [ apl_keystroke(key_name) ] end
typed_phrase(phrase,typing_speed)
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 27 def typed_phrase(phrase,typing_speed) command(phrase.chars.map do |letter| [ apl_keystroke(letter), apl_delay(typing_speed.delay_between_characters) ] end.flatten) end
Private Instance Methods
apl_delay(amount)
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 83 def apl_delay(amount) "delay #{amount}" end
apl_keystroke(name)
click to toggle source
AppleScript
Commands
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 61 def apl_keystroke(name) "keystroke #{translate_to_keystroke(name)}" end
erb_trim_mode()
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 47 def erb_trim_mode "-" end
keystroke_translations()
click to toggle source
Translate text characters to their counterpart in the world of AppleScript
.
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 73 def keystroke_translations @keystroke_translations ||= begin hash = { "\n" => "return", "\\" => "\\\\", "\"" => "\\\"" } hash.default_proc = proc { |hash,key| hash[key] = "\"#{key}\"" } hash end end
tell_application_command()
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 43 def tell_application_command ERB.new(tell_application_command_template,nil,erb_trim_mode).result(binding) end
tell_application_command_template()
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 51 def tell_application_command_template template_with_name "tell_application" end
template_with_name(name)
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 55 def template_with_name(name) File.read(File.join(File.dirname(__FILE__),"#{name}.erb")) end
translate_to_keystroke(name)
click to toggle source
# File lib/dutchman/ghost_writer/apple_script/application.rb, line 65 def translate_to_keystroke(name) keystroke_translations[name] end