class Twitterpunch::Remote

Public Class Methods

new(app=nil) click to toggle source
Calls superclass method
# File lib/twitterpunch/remote.rb, line 18
def initialize(app=nil)
  super(app)
  system('osascript', '-e' "tell application \"#{settings.remote[:apptitle]}\" to activate")
end

Public Instance Methods

photo() click to toggle source
# File lib/twitterpunch/remote.rb, line 37
def photo
  begin
    stdout, status = Open3.capture2e('osascript', '-e', "tell application \"#{settings.remote[:apptitle]}\" to activate")
    unless status.success?
      puts stdout
      raise "Could not activate Photo Booth"
    end

    # This is kind of iffy, because it depends on having full control over the UI.
    # This will only work when the Photo Booth app actually has the foreground.
    stdout, status = Open3.capture2e('osascript', '-e', "tell application \"System Events\" to keystroke #{settings.remote[:hotkey]}")
    unless status.success?
      puts stdout
      raise "Snapshot failed"
    end

    'ok'
  rescue => e
    status 500
    e.message
  end
end