Skip to content

Instantly share code, notes, and snippets.

@phyous
Created December 15, 2012 08:54
Show Gist options
  • Save phyous/4292223 to your computer and use it in GitHub Desktop.
Save phyous/4292223 to your computer and use it in GitHub Desktop.
A bash function that uses the pushover api(https://pushover.net/) to send push notifications to your phone.
############################
# Push notifications script
############################
read -d '' String <<"EOF"
require "net/https"
require "socket"
url = URI.parse("https://api.pushover.net/1/messages.json")
req = Net::HTTP::Post.new(url.path)
req.set_form_data({
:token => "APPLICATION-TOKEN-HERE",
:user => "USER-KEY-HERE",
:message => "#{ARGV[0]}",
:title => "#{Socket.gethostname}",
:priority => 1,
:sound => "pianobar",
:timestamp => Time.now.to_i
})
res = Net::HTTP.new(url.host, url.port)
res.use_ssl = true
res.verify_mode = OpenSSL::SSL::VERIFY_PEER
res.start {|http| http.request(req) }
EOF
notify() {(ruby -e $String "$@" &) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment