Class: Gasoline::Applescript
- Inherits:
-
Object
- Object
- Gasoline::Applescript
- Defined in:
- lib/gasoline/applescript.rb
Class Method Summary collapse
-
.propane_running? ⇒ Boolean
Checks if Propane is currently running.
-
.refresh_propane_if_running ⇒ Object
If Propane is running, this will send it a refresh command.
-
.run ⇒ Object
Runs a piece of Applescript,.
Class Method Details
.propane_running? ⇒ Boolean
Checks if Propane is currently running
Returns a bool
20 21 22 23 |
# File 'lib/gasoline/applescript.rb', line 20 def self.propane_running? running = run {'tell application "System Events" to (name of processes) contains "Propane"'} running == "true" end |
.refresh_propane_if_running ⇒ Object
If Propane is running, this will send it a refresh command
Returns a string
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gasoline/applescript.rb', line 28 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 |
.run ⇒ Object
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.
12 13 14 15 |
# File 'lib/gasoline/applescript.rb', line 12 def self.run value = `/usr/bin/osascript -e "#{yield.gsub('"', '\"')}"` value.gsub("\n", '') end |