Skip to content

Instantly share code, notes, and snippets.

@cmittendorf
Last active August 29, 2015 14:09
Show Gist options
  • Save cmittendorf/42d7c4c9fe6179a2c0c8 to your computer and use it in GitHub Desktop.
Save cmittendorf/42d7c4c9fe6179a2c0c8 to your computer and use it in GitHub Desktop.
A Ruby Automator action for opening all URLs and JIRA ticket ids from the input string.
require 'uri'
# without force_encoding ruby will throw an
# "invalid byte sequence in US-ASCII" exception
# when running this script from Automator
input = ARGF.read.force_encoding("UTF-8")
# scan for JIRA Ticket IDs like MYPROJECT-42
input.scan(/([A-Z]+\-[0-9]+)/).each do |id|
url = "https://<your JIRA server>/browse/#{id[0]}"
`open #{url}`
end
# extract all other URLs from the input string
URI.extract(input, ['http','https']).each do |url|
`open #{url}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment