Sha256: f4a53a505b1469340aa7b19421ff02a262f75656a7b34d3a3d400a1aa5de3318

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

module Gasoline
  class Applescript
    # Runs a piece of Applescript,
    #
    #      Gasoline::Applescript.run do
    #        "set ten_and_ten to 10 + 10"
    #      end
    #      => "20"
    #
    # Since Applescript has a nasy bit of littering its
    # return values with `\n`, already escaping those.
    def self.run
      value = `/usr/bin/osascript -e "#{yield.gsub('"', '\"')}"`
      value.gsub("\n", '')
    end

    # Checks if Propane is currently running
    #
    # Returns a bool
    def self.propane_running?
      running = run {'tell application "System Events" to (name of processes) contains "Propane"'}
      running == "true"
    end

    # If Propane is running, this will send it a refresh command
    #
    # Returns a string
    def self.refresh_propane_if_running
      return unless propane_running?

      script = <<SCRIPT
tell application "Propane"
	activate
	tell application "System Events"
		# Refresh current room
		keystroke "r" using command down
	end tell
end tell
SCRIPT

      run { script }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gasoline-0.0.3 lib/gasoline/applescript.rb
gasoline-0.0.2 lib/gasoline/applescript.rb