Perform an apple script from ruby test suite

Hi there, I am attempting to build a geolocation test around the “highway drive” built into the iOS simulator and I’d love my ruby/appium test suite to be able to kick it off itself - there is no way now within the appium library to start this type of simulation however if I can find a way to run an AppleScript I should be able to click into the iOS simulator menu and start the run from there… has anyone done anything like this? I found this example in java for pressing keyboard hotkeys for the home-button but I am not having any success porting that over to ruby http://stackoverflow.com/questions/22498745/any-way-to-put-app-in-background-and-relaunch-in-appium-ios
any help would be much appreciated.

ok that was a lot easier than I thought - all that you have to do is to run your apple script from a sub-shell using osascript - in ruby this is as simple as using ` backticks. if anyone else needs to do the same thing I’ve posted a little sample ruby-cucumber code in this repo

a few examples I’ve wrapped in ruby methods:

def foreground
     `osascript -e 'tell application "System Events" to tell process "iOS Simulator"' -e 'set frontmost to true' -e 'end tell'`
  end

  def start_highway_drive
    foreground
    exit = `osascript -e 'tell application "System Events" to tell process "iOS Simulator"' -e'click menu bar item "Debug" of menu bar 1' -e'delay 0.1' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 124' -e'key code 125'-e'key code 125'-e'key code 125'-e'key code 125'-e'key code 125' -e'keystroke "" & return' -e'delay 2' -e'end tell'`
    puts("highway drive start - #{exit.to_i}")
  end

  def stop_highway_drive
    foreground
     exit = `osascript -e 'tell application "System Events" to tell process "iOS Simulator"' -e'click menu bar item "Debug" of menu bar 1' -e'delay 0.1' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 125' -e'key code 124' -e'keystroke "" & return' -e'delay 2' -e'end tell'`
    puts("highway drive stop exits - #{exit.to_i}") 
  end

  def hit_home
    foreground
    exit =`osascript -e 'tell application "System Events" to tell process "iOS Simulator"' -e'keystroke "H" using command down' -e'delay 2' -e'end tell'`
    puts("home button exits - #{exit.to_i}")
  end

  def doubletap_home
    foreground
    exit = `osascript -e 'tell application "System Events" to tell process "iOS Simulator"' -e'keystroke "HH" using command down' -e'delay 2' -e'end tell'`
    puts("home button exits - #{exit.to_i}")
  end 

the -e flag signifies a new line in the applescript
PS I am a complete newb with applescript, if there is a better way to find and click menu items please let me know!