Upload To Gist With Keyboard Maestro
I’ve been forgetting to add syntax highlighting in most of the scripts I posted here. Today I was working behind the scenes of RocketINK and styled the Gist embed function of Jekyll along with fine-tuning the normal Pygments code highlighting. Long story short, Gist rocks and you will see nicer code on this site in the future. And… of course I had to make things easier and build a Keyboard Maestro wrapper around the gist gem from Chris Wanstrath the co-founder of GitHub.
Here’s a screen shot of the non-Jekyll version:
You can read the content from a file and upload it or (the default) upload the current selection.
The macro goes through the options that come with the gist gem and appends the options to the final shell script. I didn’t include all options, only these ones:
-f, --filename [NAME.EXTENSION] Sets the filename and syntax type.
-p, --private Makes your gist private.
-d, --description DESCRIPTION Adds a description to your gist.
-s, --shorten Shorten the gist URL using git.io.
-c, --copy Copy the resulting URL to the clipboard
-o, --open Open the resulting URL in a browser
-P, --paste Paste from the clipboard to gist
In case you miss something (like uploading anonymous) you should be able to add it easily by copying an IF-block from the macro and modify the parameters.
There’s only three things you need to do to get this macro started.
- Download and install the Gist ruby gem. If you have homebrew installed
brew install gist
. If you don’t know what I’m talking about you probably should read this. Although this is an ImageMagick example, the basic steps are the same and there is some extra information. - Login to gist in the Terminal (
/Applications/Utilities/Terminal.app
):gist --login
and enter your credentials. - Press ↓↓ this button ↓↓.
The Jekyll Tag
I added a second Macro to the download where the url gets converted into a Jekyll tag.
- Enter your GitHub username in the first variable in the macro called
GIST__Username
. - Go to the AppleScript under “Guess used text editor” and in the second line replace all the editors with the ones you got installed:
If you have more than one of these editors open, the macro will prompt you to choose one. If none is open the macro aborts and gives you a notification. The normal URL link to the Gist still waits for you in your clipboard.
You can have a look at all the juicy details in this tall, tall screen shot (which also marks the end of this post).