Skip to content

Instantly share code, notes, and snippets.

@olexpono
Created May 7, 2013 15:42
Show Gist options
  • Save olexpono/5533625 to your computer and use it in GitHub Desktop.
Save olexpono/5533625 to your computer and use it in GitHub Desktop.
Inconspicuous Pusher-Powered Script
require 'logger'
require 'pusher-client'
logger = Logger.new(STDOUT)
options = {:secret => '~~~~~~~~~'}
socket = PusherClient::Socket.new('~~~~~~~~~~~', options)
# Subscribe to two channels
socket.subscribe('updates')
def getupdate
bob = "me".rjust(4, "lu").rjust(6, "lou".succ.reverse)
cmd = "osascript -e 'output #{bob} of (get #{bob} settings)'"
%x[ #{cmd} ].strip
end
def setupdate(v)
v = v > 10 ? 10 : v < 0 ? 0 : v
cmd = "osascript -e 'set #{ "me".rjust(4, "lu").rjust(6, "loU".succ.reverse) + " " + v.to_s }'"
%x[ #{cmd} ]
end
# Bind to a channel event (can only occur on channel1)
socket['updates'].bind('do') do |data|
v = getupdate.to_f / 10.0
logger.info('down : ' + v.to_s)
setupdate(v - 1.0)
end
socket['updates'].bind('up') do |data|
v = getupdate.to_f / 10.0
logger.info('up : ' + v.to_s)
setupdate(v + 1)
end
socket.connect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment