Skip to content

Instantly share code, notes, and snippets.

@stephenbaidu
Last active August 29, 2015 13:57
Show Gist options
  • Save stephenbaidu/9713252 to your computer and use it in GitHub Desktop.
Save stephenbaidu/9713252 to your computer and use it in GitHub Desktop.
# ***********************************************************************
# Ruby script to flip through my tomod pictures for the MH370
# For Mac users only. Uses AppleScript.
# ***********************************************************************
# ***********************************************************************
# Alert
# ***********************************************************************
puts "Starting in 10 seconds"
STDOUT.flush
(1..10).each do |e|
sleep 1
print "*"
STDOUT.flush
end
puts "\nStarted"
# ***********************************************************************
# Number of columns on each row (mine is 36)
# ***********************************************************************
COLUMNS = 36
# ***********************************************************************
# Number of rows you want to scan (total of mine is 235)
# ***********************************************************************
ROWS = 3
# ***********************************************************************
# How long it takes to scan through a particular map
# ***********************************************************************
SCAN_DURATION = 5
# ***********************************************************************
# Direction variable
# ***********************************************************************
right_direction = true
(1..ROWS).each do |row|
# *********************************************************************
# Set current direction key_code 123(left), 124(right)
# *********************************************************************
key_code = (right_direction) ? 124 : 123
# *********************************************************************
# Should have been 1..(COLUMNS - 1) but it does not hurt
# *********************************************************************
(1..COLUMNS).each do |col|
# *******************************************************************
# Current cell number base on the starting row
# *******************************************************************
current_cell_no = (row - 1) * COLUMNS + col
puts "Cell: #{current_cell_no}\tRow: #{row}\t Col: #{col}"
STDOUT.flush
# *******************************************************************
# Move to the next map based on the direction key_code
# *******************************************************************
`osascript -e 'tell application "System Events" to keystroke (key code #{key_code})'`
sleep SCAN_DURATION
end
# *********************************************************************
# Move down to next row
# *********************************************************************
puts "\nMoving down to row: #{row}\n\n"
`osascript -e 'tell application "System Events" to keystroke (key code 125)'`
sleep SCAN_DURATION
# *********************************************************************
# Reverse direction
# *********************************************************************
right_direction = !right_direction
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment