Bit.ly Alfred Shortlinks

Post #2 in regards to @AlfredApp and it’s quick because I didn’t write it, I just fixed it.  I use Bit.ly links for a lot of things and there was one that I found through Google-Fu but when I tried it, it didn’t work.  You can find his work by clicking here:  kopischke.  This was a long time ago so I was just starting to learn about a lot of the things I’m STILL just starting to learn about, but at a much better rate than before.

Either way, tinkering and tooling got it back (seriously, just a URL change?  I remember this taking wayyyyy longer)  Code below and extension below or just follow the fork on his GitHub.  You’ll need to get your API key from the bit.ly guys but that should be about it.  Questions?  Throw’em in the comments:

# modified API url to align with changes to bit.ly requirements - @claylevering
# find the .alfredextension here: http://cl.ly/EEUK

declare -r API='https://api-ssl.bitly.com/v3/shorten'
declare -r LOGIN='yourlogin'
declare -r API_KEY='yourapi'

	# add http scheme to URL if none is provided
	longURL=$(printf "{query}" | sed -E -e 's|^.|http://&|' -e 's|^http://([a-zA-Z\-\.\+]+://)|\1|')

	# shorten URL
	shortURL=$(curl -sf -d "login=$LOGIN&apiKey=$API_KEY" --data-urlencode "longURL=$longURL" -d "format=txt" $API)

	declare -i curlExit=$?
	if [ -n "$shortURL" ]; then
		printf $shortURL | pbcopy
		echo "Bit.ly Generated!"
		echo $shortURL
		exit 0
	elif [ $curlExit -eq 22 ]; then
		errMsg="URL '$shortURL' could not be shortened because of a bit.ly server error. Your URL, login or API key may be invalid, or bit.ly may be experiencing technical difficulties."
	else
		errMsg="URL '$longURL' could not be shortened because of a technical error. The 'curl' command returned with exit code $curlExit. Check the man page for curl for details."
	fi # [ -n "$shortURL" ]

And the extension is here: Bit.ly Shortlink.alfredextension

Canned Sparrow e-mails with Alfred

The Alfred Butler's Hat

AlfredApp.com

This is my first post, and I warn you all by mentioning I’m a novice scripter.  My knowledge comes primarily through mass googling as I have no resources locally that have the time, patience, or even knowledge to help me on my own.  So here goes:

With Alfred 1.1 we have the ability to throw highlighted text directly to a parameter in Alfred.  So for example, dealing with Social Media and Customer Support I wanted a tool i could use from my computer without having to open anything where I could grab some text, toss to Alfred and have it generate an e-mail with that text and send it out to my ticket processing CRM.  This lets me focus on the content and later I can go back in and re-tag and edit the tickets I’ve created (and the metrics that now work!).  So I wanted two things:

  1. The ability to create a “Blank” version of my canned message that allowed me to add some notes if I wanted to but that created the ticket e-mail as normal
  2. The ability to create a “Filled” version of my canned message including the highlighted text I had so I can get back to where I saw the important item – most of the time, this ends up being a URL to a tweet or something.

I created the following AppleScript Extension.  At first, I had a bit of problems getting the parameter checked out, but with the help of @AlfredApp and @BinaryGhost, we managed to figure it out:

on alfred_script(q)
	set q to q as text
	if (q is equal to "") then
		log "no parameter"
		set alfredInput to "Other"
		set q to "Other"
	else
		log q
		set alfredInput to q
	end if

	using terms from application "Sparrow"
		tell application "Sparrow"
			activate
			set theMessage to make new outgoing message with properties {subject:"CANNED EMAIL SUBJECT - PARAMETER:  " & alfredInput, content:"All

This is a canned e-mail being generated by Alfred using an AppleScript Extension.  If it contains a parameter, it will be listed below and in the subject.

PARAMETER:  " & alfredInput & "
Details (optional):  ", message signature:"YOUR SIGNATURE"}
			tell theMessage
				make new to recipient at end of to recipients with properties {name:"RECIPIENT NAME", address:"RECIPIENT@EMAIL.ADDRESS"}
				compose
			end tell
		end tell
	end using terms from
end alfred_script

As you can see in this code the variable “alfredInput” is what will be replaced by the parameter provided and if it is not given, it will default to the text, “Other”.  There are a couple of nice features you can toggle in and out of this – the way I’ve written it the cursor will “end” following “Details:  ” allowing you to trigger the extension and then begin immediately adding details to whatever it is you’ve started.

Alternatively, you can replace “compose” with “sendmessage” for a truly canned message that will send automatically.

Feel free to grab the extension here: Canned Sparrow E-Mail.alfredextension

A résumé of sorts

Hello all!

I figured I would get this started by posting a résumé of sorts.  My name is (obviously) Clay Levering and I am here as both a tech enthusiast and what I imagine as some type of “ultimate geek.”  But sometimes it takes a lot to really understand what that means about people – I mean everyone has that one person they know that does tech stuff – but I’m the person THOSE people come ask questions:  Seriously.  So this is my résumé so to speak. You can do with it what you’d like, but all you really need to know is that I’m going to be able to answer your question, just as simple as that.

Continue reading