Class: Castanaut::OS::MacOSX::TigerMovie

Inherits:
Movie
  • Object
show all
Defined in:
lib/castanaut/os/mac_os_x_legacy.rb

Overview

The TigerMovie class is intended to work on machines running Mac OS X 10.4.x. In order for it to work correctly, the Extras Suites application must be installed.

Get it at <www.kanzu.com/main.html#extrasuites>

KNOWN LIMITATIONS

Not supported:
* Movie#mousedown
* Movie#mouseup
* Movie#drag

Partially supported:
* click - only work with left-clicks

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Movie

#click_menu_item, #execute_applescript, #launch, #say, #screen_size, #type_via_applescript

Methods inherited from Movie

#_play, #_play_and_monitor, #at_end_of_movie, #by, #initialize, #launch, #offset, #pause, #perform, #plugin, register, #run, #say, #screen_size, #script, #skip, spawn, #to, #while_saying

Constructor Details

This class inherits a constructor from Castanaut::Movie

Class Method Details

.platform_supported?Boolean

Returns true if the current platform is Mac OS X 10.4.

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 26

def self.platform_supported?
  vers = `/usr/bin/sw_vers -productVersion`.match(/10\.(\d)/)
  vers[1].to_i == 4
rescue
  false
end

Instance Method Details

#click(btn = "left") ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 115

def click(btn = "left")
  not_supported "anything other than left clicking"  unless btn == 'left'
  execute_applescript(%Q`
    tell application "Extra Suites"
      ES click mouse
    end tell
  `)
end

#cursor(*options) ⇒ Object


MOUSE INPUT DIRECTIONS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 66

def cursor(*options)
  options = combine_options(*options)

  apply_offset(options)
  @cursor_loc ||= {}
  @cursor_loc[:x] = options[:to][:left]
  @cursor_loc[:y] = options[:to][:top]


  start_arr ||= execute_applescript(%Q`
    tell application "Extra Suites"
      ES mouse location
    end tell
  `).to_s.split(',').collect{|p| p.to_s.to_i}
  start_loc = {:x=>start_arr[0], :y=>start_arr[1]}
  dist = {
    :x=>(start_loc[:x] - @cursor_loc[:x]),
    :y=>(start_loc[:y] - @cursor_loc[:y])
  }
  steps = dist.values.collect{|p| p.to_s.to_i.abs}.max / 10.0

  dist = {:x=>dist[:x] / BigDecimal.new(steps.to_s), :y=>dist[:y] / BigDecimal.new(steps.to_s)}

  execute_applescript(%Q`
    tell application "Extra Suites"
      set x to #{start_loc[:x]}
      set y to #{start_loc[:y]}
      repeat while x #{dist[:x] > 0 ? '>' : '<'} #{@cursor_loc[:x]} or y #{dist[:y] > 0 ? '>' : '<'}  #{@cursor_loc[:y]}
        ES move mouse {x, y}
        set x to x - #{dist[:x].round(2)}
        set y to y - #{dist[:y].round(2)}
        delay 1.0E-6
      end repeat
      ES move mouse {#{@cursor_loc[:x]}, #{@cursor_loc[:y]}}
    end tell
  `)
end

#cursor_locationObject



105
106
107
108
109
110
111
112
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 105

def cursor_location
  loc = execute_applescript(%Q`
  tell application "Extra Suites"
    ES mouse location
  end tell
  `).split(/\D+/)
  {:x => loc[0].to_i, :y => loc[1].to_i}
end

#doubleclick(btn = "left") ⇒ Object



125
126
127
128
129
130
131
132
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 125

def doubleclick(btn = "left")
  not_supported "anything other than left clicking"  unless btn == 'left'
  execute_applescript(%Q`
    tell application "Extra Suites"
      ES click mouse with double click
    end tell
  `)
end

#drag(*options) ⇒ Object



157
158
159
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 157

def drag(*options)
  not_supported("drag")
end

#hit(key, *modifiers) ⇒ Object


KEYBOARD INPUT DIRECTIONS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 38

def hit(key, *modifiers)
  script = ''
  if key == '"'
    type(key)
    return
  elsif key.index('0x') == 0
    script = hit_with_system_events(key, *modifiers)
  else
    script = hit_with_extra_suites(key, *modifiers)
  end
  execute_applescript(script)
end

#keystroke(*args) ⇒ Object



52
53
54
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 52

def keystroke(*args)
  not_supported("keystroke")
end

#mousedown(*args) ⇒ Object



147
148
149
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 147

def mousedown(*args)
  not_supported("mousedown")
end

#mouseup(*args) ⇒ Object



152
153
154
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 152

def mouseup(*args)
  not_supported("mouseup")
end

#tripleclick(btn = "left") ⇒ Object



135
136
137
138
139
140
141
142
143
144
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 135

def tripleclick(btn = "left")
  not_supported "anything other than left clicking"  unless btn == 'left'
  execute_applescript(%Q`
    tell application "Extra Suites"
      ES click mouse
      ES click mouse
      ES click mouse
    end tell
  `)
end

#type(str, opts = {}) ⇒ Object



57
58
59
# File 'lib/castanaut/os/mac_os_x_legacy.rb', line 57

def type(str, opts = {})
  type_via_applescript(str, opts)
end