Jump to content

Hotkey that "does the right thing" with selected text


Recommended Posts

I'm building a workflow that uses "double-shift" as a hotkey to do things with selected text. For example, at work I have two different ticket systems, one prefixes IDs with "CNVS" (e.g. CNVS-1234) and the other with "g/" (e.g. "g/54321"). I'd like to be able to highlight either of these, tap "double-shift" and have it send me in a browser to the correct ticketing system.

 

What's the best way to achieve this with workflows? Can I avoid making a script in this case?

 

Thanks,

Duane Johnson

Link to comment
What's the best way to achieve this with workflows? Can I avoid making a script in this case?

 

Just to be clear, I understand how to do this with ONE ticket prefix... it's a simple matter of connecting the Hotkey trigger to the Open URL action. What I'm trying to understand is how Alfred might be able to help me in pattern matching the prefixes so it can choose the correct Open URL action.

Link to comment
def notify(msg, title = "Tell Me More")
	begin
		require 'rubygems'
		require 'terminal-notifier'
		TerminalNotifier.notify msg, :title => title
	rescue
		`growlnotify -n "#{title}" -m "#{msg}"`
	end
end

url = case "{query}".strip
when /^CNVS-(\d+)$/ then
	"https://mycompany.atlassian.net/browse/CNVS-#{$1}"
when /^g\/(\d+)$/ then
	"https://gerrit.mycompany.com/#/c/#{$1}"
else
	notify "I can't tell you more about {query}"
end

`open "#{url}"`

# Log of IDs we've recently visited
`echo "#{url}" >> ~/.tellmemore`

 

 

For posterity, the above script accomplished my aims. In workflows, I connected "Hotkey" to "Run Script" and chose Ruby as the language. It uses an optional TerminalNotifier ruby gem [1], or if unavailable, tries to use growlnotify.

 

[1] https://github.com/alloy/terminal-notifier

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...