pattulus
1/13/2014 - 3:17 PM

Launchbar action to create public gist

Launchbar action to create public gist

-- 
-- gist support for launchbar
-- 1. install gist client "sudo gem install gist"
-- https://github.com/defunkt/gist
-- 2. login "gist --login"
--
-- use from launchbar as file action, string/search action, or
-- plain action (will take text from clipboard)
-- then will put gist url as launchbar result
-- from there you can Copy it or hit Enter to open in browser
--

-- take string from LaunchBar and create public gist
on handle_string(theText)
	try
		set gistCmd to "echo " & quoted form of theText & " | gist"
		set gistUrl to (do shell script gistCmd)
		tell application "LaunchBar"
			set selection as text to gistUrl
			activate
		end tell
	on error e
		tell application "LaunchBar" to display in large type "Error: " & e
	end try
end handle_string

--take contents of a file (text) and create public gist
on open (theFile)
	try
		set pFile to (POSIX path of theFile) as text
		set gistCmd to "cat " & quoted form of pFile & " | gist --filename " & quoted form of pFile
		display dialog gistCmd
		set gistUrl to (do shell script gistCmd)
		tell application "LaunchBar"
			set selection as text to gistUrl
			activate
		end tell
	on error e
		tell application "LaunchBar" to display in large type "Error: " & e
	end try
end open

-- otherwise as straight action create public gist from clipboard
set clip to the clipboard
handle_string(clip)