Alfred ProTips

If you read this blog then you probably already know how awesome Alfred is and how much I love finding new and creative ways to use it. The developers have just launched version 0.9 [non MAS version] and it is, without a doubt, a game changer. Why? Because they have added the ability to assign shortcuts to scripts for those who have purchased the Powerpack. Let’s stop and think about that for a second, anything that is scriptable, is now launch-able from Alfred with an abbreviated keyword or Global Hotkey. When I got my hands on this version, I went nuts scripting all types of things. Scripts I use to launch with TextExpander or Hazel, seemed even more natural with Alfred. So I’m going to show you some of the ways you can use a handful of these new features while also demonstrating some black belt level tricks with Alfred.

Shorten a URL with Goo.gl:


This was the first command I added after getting my hands on Alfred 0.9. I got the idea after the developer asked if someone could do this on Twitter several days prior. Of all the things I wanted to script, I knew this would probably be the easiest, so thats where I started, and then shared it with the developers. The code is simple, one line actually. Here are the settings you will enter under Alfred’s new section Terminal/Shell. Be sure to check the Silent box next to your command in the Terminal Shortcuts window within Alfred to make this script run in the background.

Download extension here: Create Goo.gl Link

To use this tool, simply type gl followed by a URL that you paste in to the Alfred window as shown below. When you hit enter, the shortened link is added to your clipboard.

Create a CloudApp bookmark right in your clipboard:


This one was a bit trickier to figure out. I read through the REST API documentation which was really helpful. So instead of just posting a specially crafted url, this one requires we send formatted JSON, and it returns a result in JSON format. This is a great example of calling an external script with Alfred. In this script I also added a growl notification to let you know the link has been added to your CloudApp account, because you will also run this script as Silent under Alfred’s settings. There is no indication if it fails but the notification is a nice indication that something happened.

Again, just setup your new Terminal/Shell action as shown below (obviously change the path to the script to match your script location). If you want a nice image to go along with it, CloudApp has a great presskit available. I also want to point out that this script functions differently from the Goo.gl command. I did this on purpose to demonstrate the different ways to utilize scripts in Alfred 0.9. With this script, Alfred is not passing the URL as a variable because cloudapp.sh is reading your clipboard for the URL and creates a shortened Cloudapp link which is then copied to your clipboard. Honestly, this would probably be better just mapped to a Global Keyboard Shortcut, but I will get to that later. Another great tip is, in Safari, use Command + L to highlight the URL bar and you can quickly copy the address of any site you are viewing without taking your fingers off the keyboard, it’s nice. Another great thing about using Alfred for CloudApp links is it works in any app that you can copy a link, no Rain Drop necessary.
[Update] By the time this publishes, CloudApp 1.5 will have been released which has a feature that makes this a bit obsolete, but its finished so I’m not going to remove it :)


Here is the code to add to your cloudapp.sh script. Be sure to add in your own Username and Password.

Download extension here: Create CloudApp Link

*This script also works well with TextExpander. Just remove the last part of the echo line, “| pbcopy” and TextExpander will simply print the shortened url right where you are typing.

Convert video to AppleTV format:


Ok, this one is by far my favorite. I have used Handbrake forever but have never automated it all. Whenever I download a new TV show or something I always fire up the GUI, select my preset, browse for the file, and wait for it to finish. With this script, I use HandBrakeCLI (which is a separate install, but totally worth it) to do all the heavy lifting. Now I know what you are going to say: Don, you know Handbrake uses ffmpeg for converting video so why not just cut out the middle man and use ffmpeg in your script like the living legend Brett Terpstra? Well for one, I love Handbrake and it does a great job with little configuration. Since I am only using this script for videos on the AppleTV 2, I can use the Handbrake preset for that device and call it a day…(I’m lazy).

So what’s different about this script? Well this one will be run as an Action (a new option in Alfred’s Action Panel) so you will have to check the Action box in the Terminal settings as shown below. I thought about also marking it Silent, but I like seeing the terminal window during the conversion. Here is the general workflow for an Action like this: Select a video > hit the shortcut Control + Command + \ (pulls up Alfred’s Navigation window) > arrow down to your new action labeled Transcode video for AppleTV. Since videos generally take about 10 minutes to convert, not only does this script send a Growl notification, but it will play a System Sound to notify you when your video is done converting.

Download extension here: Convert to AppleTV Format

[UPDATE 6/02/2011 01:49:03PM]

The wise and creative reader, Andreas Heiberg, that fixed this script when I first posted it, has posted his own enhanced version that allows you to queue movies and even shows the conversion status in Alfred’s bar. Very Nice! Check it out here: Alfred: Convert files to an Apple Tv compatible format

Upload file to Amazon S3


You can easily create an Action for uploading to Amazon S3 by installing s3cmd and slightly modifying the shell script from my previous post Scripting S3 Image Uploads. This utilizes a system alert sound, Growl notifications, and when its done uploading it creates a link to your S3 file in your clipboard. It even encodes any spaces to “%20″ so you can paste it right in to your browser, or share it easily! Be sure to check the box to Escape spaces with backslashes for {query} parameter as shown below. Also check the preference boxes for both Silent and Action. What is really sweet is when you start combining these actions in your workflow. Example: Select a file > Bring up Alfred’s File Navigation > choose Upload to Amazon S3 (the link to that file gets copied to your clipboard) > pull up Alfred and type cl > Paste your new CloudApp bookmark to your S3 file anywhere you want. Easy. Be sure to add your S3 Bucket name to the script.

Download extension here: Upload to Amazon S3

Miscellaneous Roundup


I have so many more that I couldn’t squeeze in to this already long post, but here are a few honorable mentions:

Create Custom Bit.ly Shortened URL:

Not much to say about this one, I got a request to publish this from someone on Twitter, so here it is. It functions the same as the goo.gl example earlier. You do have to add your API and login name to use Bit.ly’s service, but this script worked fine for me. It even used my custom domain under my Pro Account settings with no additional configurations!

Download extension here: Create Bit.ly link

Upload Picture to Picasa

You can install the great GoogleCL and create an Action for uploading pictures to Picasa. The function of this workflow would be similar to the HandBrake example. Be sure to check the box to Escape spaces with backslashes for {query} parameter as shown below:


Run OmniFocus AppleScripts with Global Hotkeys:

3. You can assign any script, including any afore mentioned scripts in this post, to Global Hotkeys (I really could do a whole post just on utilizing this feature). I immediately put this to work with some OmniFocus scripts I commonly use. I also thought this would have been a great option of the CloudApp script since it did not need any input from Alfred but I wanted to demonstrate the different ways to launch a script.

Here is an example of how I am using it:


These are two scripts from Dan Byler. One changes dates to the weekend, and the second one moves dates by a certain amount of days that I specify.

Use Alfred for Window Management:

I actually really like this one, but since I didn’t want to show the code for all 9 scripts I decided to tack it on to the end of the miscellaneous section. This is basically combining Alfred’s Global Hotkey feature with 9 different Applescripts that will resize/relocate the front window to a specific location on the screen, kind of like the app Divvy. As far as I know this only works for one monitor and the height and width of the resolution are static variables so you have to change them to match your own resolution (mine is 1280×800). If you frequent between multiple resolutions, Gruber has a tip for just autodetecting your resolution. I believe this only works for apps that have AppleScript support.

So here is a link to a zipped folder of the AppleScripts you will need:

Window Management AppleScript Download

Here are my settings for this, I just used COMMAND + OPTION + a number:


I really love this new Global Hotkeys feature in Alfred. It is a lot like FastScrips, so those familiar with that program should feel right at home.

Well that’s it for now. Feel free to let me know how you guys are using the new features in Alfred and I’ll update this post. Enjoy!

[UPDATE 5/18/2011 04:02:45PM]

Start a screencast from Alfred:

This one is great. It utilizes Quicktimes’s ability to record your screen. It launches with a screencast cast command. It creates a video in your Movies folder.

Download extension here: Start a Screencast

View MAN pages in Preview.app instead of the terminal

This one may not apply to everyone but I sure do read a lot of man pages. Its great to be able to get them out of the terminal in a more readable format. From Alfred, just type man followed by one or more terminal commands you want to view man pages for. No Quotes for this one!

Download extension here: View Man page in Preview

I am just going to keep updating this post as I come up with more so stay tuned!

[UPDATE 5/19/2011 09:15:39AM]

Set wallpaper from Alfred action menu

This one is a user request from John Pappas. Similar to the transcode workflow, you select a photo in Finder, pull up Alfreds actions and scroll down to the new Set as Desktop Wallpaper.

Download extension here: Set as Wallpaper

[UPDATE 5/22/2011 03:48:54PM]

Create tasks in OmniFocus with Natural Language

This one is by far my greatest accomplishment. An Alfred script so large it needed its own post. You can find it here:

OmniFocusCLI: Natural Language Tasks from Alfred

[UPDATE 5/24/2011 09:00:35AM]

Share your current song from iTunes or Ecoute

This quick tip takes the current song from either iTunes or Ecoute and formats a #NowPlaying tweet ready to paste in to any Twitter client. It also shows a Growl notification of all the details and for you Ecoute users, the Growl icon is the album artwork for the current track! I just launch it from Alfred with a “np”

Download extension here: Now Playing

Action Shot:

[UPDATE 8/03/2011 09:49:28AM]

Share on Dropbox with CloudApp Short URL

This one copies a file to your Dropbox public folder and creates a CloudApp URL to it. Be sure to update the script with your Cloudapp Credentials and Dropbox ID.

Download extension here: Share on Dropbox

Create Secure DMG from selected folder

Download extension here: Create Secure DMG

Print from Alfred

This one will need to be tweaked with the name of your printer

Download extension here: Print Document

Rename file from Alfred

This will prompt for a new filename. You can enter just the new name or if you want to change the filetype you can enter the new name and an extension.

Download extension here: Rename File

Password Generator for Alfred

This will generate a random password and put it in your clipboard as well as a sticky Growl notification.

Download extension here: Generate Password

Image Dimensions

This action will display the dimensions of the currently selected image

Download extension here: Image Dimensions

Display CPU Temperature

Download extension here: Display CPU Temperature

Compare two files in BBEdit

Download extension here: Compare in BBEdit

Hash a password using PwdHash.com project

This one reads the URL from your clipboard, and gets a password from the Alfred input. See PwdHash.com for how this hash method works.

Download extension here: Hash a password

Toggle System Files – Visible/Hidden

This one reads the current view status of system files and just toggles it.

Download extension here: Toggle System Files

Convert Image Formats

This one toggles an image format from JPEG to PNG or PNG to JPEG depending on the current format.

Download extension here: Convert Image Format

Change iChat Status

This one toggles your current iChat status in between Available and Away. It also sets a custom status message based on user input from Alfred.

Download extension here: Change iChat Status

Create iOS 5 Reminders Tasks

This is a quick and simple Alfred extension that creates a new basic todo at the end of the “Reminders” calendar. Nothing new or ground breaking here but it is really convenient now that it syncs to the Reminders app on iOS 5. I also added some code to Growl after it finishes, hopefully Growl works (it did for me) but no guarantees!

Here is a link to the Alfred Extension: Create Reminders Task

  • http://www.scoobydoofus.com Scoobydoofus

    Nice! The bit.ly one in particular could be useful, thanks!

  • http://twitter.com/JoeKueser Joe Kueser

    Amazing tips. Thanks!

  • http://leandroardissone.com/ Leandro A.

    Excellent tips..!
    Is there a way to create links under your Google account from terminal?

  • Guest

    This is awesome. Thanks a lot.

    I’m trying to set up transcoding, but whenever I run it, Terminal says that access to my shell script is denied. There’s probably an obvious solution that I’m too stupid to think of, but any tips?

  • Anonymous

    I would check the permissions on your script.

    you could run “chmod 775 transcode.sh” from the terminal to give it permissions to run.

  • Anonymous

    Possibly, what do you mean by “links under your Google account”?

  • http://leandroardissone.com/ Leandro A.

    Like non anonymous. Then you can see your shorted links in your account at http://goo.gl/ where you can see the links stats.

  • Anonymous

    Oh! that would be very neat, but Google needs to open an API like bit.ly has for such a script to work. But I will update the script if I do find a way :)

  • Brownlaronn

    Where do the files go once converted with the script

  • Anonymous

    The same directory as the original file.

  • Pingback: Alfred tips – 52 Tiger

  • Guest

    Might want to consider obfuscating the filename in your HandBrake script. Someone is sure to whine.

  • Anonymous

    Appreciate you looking out :) I didn’t even think of that, but it’s been updated!

    Thanks.

  • Yohannes Wijaya

    Don, continuing from your cloudapp tip, how can I parse a file to a script that will upload it? What script modification is needed?

  • Oscar

    Excellent. I have one problem with bit.ly. Instead of pasting the shortened URL to the clipboard, it opens the bit.ly website. I have copied the code exactly as it is and entered my api Key and login name.

  • http://niklasm.se/ niklasm

    Thank you for your excellent (and inspirational) tips. Just one suggestion: there’s a Growl command-line tool available at http://growl.info/extras.php which means you don’t have to use AppleScript for the notifications. It will save you a few lines of code and, presumably, some execution time.

  • http://niklasm.se/ niklasm

    Never mind, I did some testing and it seems the CLI tool needs a terminal window to display notifications. Which I guess is the reason why you resorted to AppleScript.

  • Pingback: Astuces : aller plus loin avec Alfred 0.9 | l-atelier-bois

  • http://pt-br.facebook.com/gamabruno Bruno Gama

     i’ve added a growl notification in the goo.gl url shortener script, but you have to install the growlnotify in the command line.

    curl -s –data-urlencode “url={query}” http://goo.gl/action/shorten | grep “goo.gl” | awk -F” ‘{print $(NF-1)}’ | awk ‘BEGIN { FS = “=” } ; { print $2}’ | pbcopy; CLIPBOARD=`pbpaste`; growlnotify –image /Users/windu/Pictures/icons/Applications Icons/google-48×48.png -t “URL Shortened” -m ${CLIPBOARD}

  • http://pt-br.facebook.com/gamabruno Bruno Gama

     i’ve added a growl notification in the goo.gl url shortener script, but you have to install the growlnotify in the command line.

    curl -s –data-urlencode “url={query}” http://goo.gl/action/shorten | grep “goo.gl” | awk -F” ‘{print $(NF-1)}’ | awk ‘BEGIN { FS = “=” } ; { print $2}’ | pbcopy; CLIPBOARD=`pbpaste`; growlnotify –image /Users/windu/Pictures/icons/Applications Icons/google-48×48.png -t “URL Shortened” -m ${CLIPBOARD}

  • http://twitter.com/jobbogamer Josh Sunshine

     Great tips!
     
    I’m having problems with the HandbrakeCLI one though. When I try to run the script I get the error:
    /Users/Josh/Library/Scripts/transcode.sh: line 8:   350 Segmentation fault      /usr/local/bin/HandBrakeCLI -i “$1″ -o “$VIDEO”.m4v –preset=”AppleTV 2″

    Not sure what that means, as I don’t work with command-line stuff too often. Any help would be greatly appreciated :)

  • http://twitter.com/jobbogamer Josh Sunshine

     Thanks for getting back to me. Running the command by itself works fine. I wonder if Alfred is doing something screwy somewhere.

  • Anonymous

    How is that task setup in Alfred? I am using it without quotes but I check the box for spaces to be slashed.

    settings:
    http://cl.ly/6rEa

  • http://twitter.com/jobbogamer Josh Sunshine

    OK, interesting development; calling it from Alfred works fine from the Desktop but not from anywhere else.

    And I have it set up the same as you, spaces but not quotes.

  • Anonymous

    Hmmm. I am not able to recreate your issue, but maybe this post will offer some guidance …. I found it through Google so it may offer no help at all but here you go: http://mrdickie.wordpress.com/2009/08/09/handbrake-0-9-3-segmentation-fault/

  • Can

    Awesome

    I really like Alfred. :) )

  • http://twitter.com/MarcoBii Marco Braglia

     hey thx for these amazing tips!
    I’m using so much the window management, but now I have a problem with the VLC screeencast, I’m not able to save the script.
    apple script editor reply me “Expected end of line, etc. but found “/”.”
    highlighting the firs / of the code before Applications..I’m so bad in programmation

  • John Pappas

     Excelent! Can you make one to set a picture as desktop picture, please?

  • http://www.twitter.com/binaryghost Don Southard

    Ask and you shall receive :)

  • Pingback: Check Out These Pro Alfred App Tips From Don Southard | iSource

  • Anonymous

    I wouldn’t use Apple Script Editor, just use a plain text editor and save it as a .sh file. 

  • Matt Garrett

    Love the scripts…for your windows position scripts, just change your mywidth/myheight to:
    tell application “Finder”
        set _b to bounds of window of desktop
        set myWidth to item 3 of _b
        set myHeight to item 4 of _b
    end tell

    Doing it this way will make it work on any screen resolution, and calculate it based on the set resolution.  

  • Jared Flack

    Thanks for the great scripts! I’ve been using your goo.gl link shortening script for awhile and just thought of replacing {query} with $(pbpaste) since I usually copy and paste the URL in anyways..it does force you to copy it first.

    curl -s –data-urlencode “url=$(pbpaste)” http://goo.gl/action/shorten | grep “goo.gl” | awk -F” ‘{print $(NF-1)}’ | awk ‘BEGIN { FS = “=” } ; { print $2}’ | pbcopy

    How did you figure out the goog.gl/action/shorten thing? Is it in the API somewhere?

  • Anonymous

    Its not an exciting story, I just knew Google didn’t have an API yet so I just picked apart their website where you can create Goo.gl links and found that URL. I knew cURL could POST, so the hard part was figuring out how to parse the output. I’m glad people are using it though!

  • Andreas Heiberg

    I love the handbrake script you made, however I had to modify it to get it to work. I thought I would share my fix with everyone. I basically ran into a situation where my files wouldn’t convert because you change the name of the destination folder on line 6, my simple fix was to delete line 6 and then edit what becomes line 6 to say “VIDEO=${INPUT%.*}”. Thats all I changed to make it work (except for the placing of my HandBrakeCLI file)

  • Anonymous

    Hey, thanks for fixing that! I updated the script and credited you!

    Don.

  • Pingback: Project/Class Generation using Project Sprouts and Alfred App

  • Pingback: Alfred

  • http://twitter.com/relyb relyb

    Ran across this post. Great Alfred tips (I use LaunchBar but most apply quite well), and I’m glad you like my OmniFocus scripts! :)

  • http://twitter.com/dbyler Dan Byler

    Great tips—I’m a LaunchBar user but many of these apply as well. Also, glad you like my OmniFocus scripts! :)

  • Anonymous

    Thanks man! your scripts are awesome, they are the only ones I use that I didn’t write myself. You are a legend and I am honored you read my article! I am kind of nerd star struck right now :)

  • Andreas Heiberg

    I have some other fixes for you if you want – or rather improvements. Would you care for a conversation about this? over email or something? You can always send me a pm on twitter at AndHeiberg so we can figure something out.

  • Anonymous

    Sure, send them to support (at) dirtdon (dot) com

    Don Southard
    Omaha, NE
    402.577.0101
    Email (mailto:binarydirt@gmail.com) | Homepage (http://www.dirtdon.com)

  • Pingback: Alfred: Convert files to an Apple Tv compatible format « Andreas Heiberg

  • http://www.marcelboast.com Marcel

    fantastic tips! I have so much Alfred love, awesome program

  • Jonas

    Having trouble with the Weather script. Can’t get the temp and condition to show up in the command description.

  • Anonymous

    Did you make sure to change the DIR variable in the weather script to reflect the location of your Alfred directory? If so, try to run the script from the Terminal and see if it gives you a useful error message.

    Don.

  • Jonas

    Ran it, gave me a (for me) unuseful error: 70:71: syntax error: Expected expression but found unknown token. (-2741)

  • http://www.twitter.com/binaryghost Don Southard

    Syntax error usually means something in the code is written incorrectly, but I use it everyday so I know it works. I think we should switch this convo to email. Can you send me an email at support (at) dirtdon (dot) com and attach your shell script exactly as it is. I will take a look and rewrite it for you, if need be.

    Don.

  • Runar Dankel

    When you paste the script it will give you HTML code like: 

    href=”http://gtwthr.com/$CODE/temp`”>http://gtwthr.com/$CODE/temp`

    Change that to:

    http://gtwthr.com/$CODE/temp