Skip to content

Instantly share code, notes, and snippets.

@netikular
Last active August 29, 2015 14:07
Show Gist options
  • Save netikular/df74a1435668504ca0e4 to your computer and use it in GitHub Desktop.
Save netikular/df74a1435668504ca0e4 to your computer and use it in GitHub Desktop.
Ruby script and AppleScript snippets for configuring a Pomodoro timer to integrate with hip chat. Inspiration from http://afitnerd.com/2013/08/19/pomodoro-hipchat-automate-availability/
tell application "System Events" to tell UI element "HipChat" of list 1 of process "Dock"
perform action "AXShowMenu"
delay 0.5
click menu item "Status" of menu 1
click menu item "Available" of menu 1 of menu item "Status" of menu 1
end tell
do shell script "<path to hipchat_notification.rb> 'is back from his pomodoro'"
#!/usr/bin/ruby
require 'net/http'
require 'uri'
require 'json'
# Usage:
# ./hipchat_notification.rb <message>
# API documentation: https://www.hipchat.com/docs/apiv2/method/send_room_notification
# Get a version 2 api key from the user interface
# https://<your group name>.hipchat.com/account/api
API_KEY=''
# Use to output room information
# You will need to use it to get the id of the room you want to post into
# and put that number into the constant ROOM_ID below.
=begin
uri = URI.parse("https://api.hipchat.com/v2/room")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Get.new(uri)
req['Authorization'] = "Bearer #{API_KEY}"
res = http.request(req)
puts "ID\tName"
JSON.parse(res.body)['items'].each do |room|
puts %{#{room['id']}\t#{room['name']}}
end
=end
ROOM_ID = 0000000
uri = URI.parse("https://api.hipchat.com/v2/room/#{ROOM_ID}/notification")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new(uri.path, { 'Authorization' => "Bearer #{API_KEY}", 'Content-Type' => 'application/json' } )
req.body = %{{ "message": "#{ARGV[0]}", "color": "green"}}
res = http.request(req)
tell application "System Events" to tell UI element "HipChat" of list 1 of process "Dock"
perform action "AXShowMenu"
delay 0.5
click menu item "Status" of menu 1
click menu item "Available" of menu 1 of menu item "Status" of menu 1
end tell
do shell script "<path to hipchat_notification.rb> 'had a failed pomodoro! Too many distractions!'"
tell application "System Events" to tell UI element "HipChat" of list 1 of process "Dock"
perform action "AXShowMenu"
delay 0.5
click menu item "Status" of menu 1
click menu item "Available" of menu 1 of menu item "Status" of menu 1
end tell
do shell script "<path to hipchat_notification.rb> 'bailed on his pomodoro!'"
tell application "System Events" to tell UI element "HipChat" of list 1 of process "Dock"
perform action "AXShowMenu"
delay 0.5
click menu item "Status" of menu 1
click menu item "Do Not Disturb" of menu 1 of menu item "Status" of menu 1
end tell
do shell script "<path to hipchat_notification.rb> 'is starting a Pomodoro. He will be back in 25 minutes.'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment