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

  • Runar Dankel

    Sry Jonas. I see what you getting at now. Get the same error.

  • http://twitter.com/gotofritz fritz

    Great stuff in there, thanks.

    for a minute I misread one tip as “Change weather from Alfred…”

  • Anonymous

    Thank you for the excellent article! This stuff finally brings Alfred in line with QS.

  • Pingback: Alfred Extensions: The best scripts (so far!) « Alfred App – Mac OS X Quicklaunch Application

  • http://twitter.com/jiserra Juan Ignacio

    Awesome scripts! BTW, I love your Growl skin, where did you get it?

  • Anonymous
  • http://twitter.com/jiserra Juan Ignacio

    Great, thanks!

  • spiderand

    I noticed you have removed the image convert toggle from PNG to JPG script. 

    Did Lion break your ImageMagick install like mine? Any ideas how to fix it? I’m crap with the terminal.

  • Anonymous

    Yeah thats exactly why I removed it. I couldn’t get ImageMagick to work correctly and don’t have to time or desire to figure it out.

  • SeaMonster

    Having trouble with this script as well. I cannot get the subtitle to display anything but the message that I type through the Alfred interface in the “Description” area, even though the growl message displays the variables correctly. My DIR variable is set correctly, and everything else about the script is performing as expected. My error message from the terminal is as follows:
    70:71: syntax error: Expected expression but found unknown token. (-2741)

  • Guest

    Bit.ly code is incomplete. Try this one:

    apiKey=”YOUR_API_KEY”
    login=”YOUR_LOGIN”
    curl -s –data “uri={query}&apiKey=$apiKey&login=$login&longUrl=$1&format=txt” http://api.bitly.com/v3/shorten | tr -d ‘n’ | pbcopy
    echo “Message to show in Growl”

  • Anonymous

    Thanks for catching that! I switched from it being an external shell script to Alfreds internal script this morning and must have forgot to update the input variable.

    Don.

  • http://twitter.com/iammerrick Merrick Christensen

    iChat integration?

  • Anonymous

    I added a new extension for toggling PNG and JPEG formats that doesn’t require IM if you are interested.

    Don.

  • Anonymous

    These scripts are amazing – thanks!

    One small issue with the share on dropbox with cloudapp URL script: it breaks with spaces in filenames. Looks like dropbox needs to append ‘?w=877b912d’ to the URL in those scenarios; is there any way you can do a space detection and if so add that parameter? I’d do it myself but I lack the necessary skillz…

    (Thanks again!)

  • Anonymous

    Thats strange, I took spaces in to account by encoding them with %20. It seems to work fine for me. Heres a screen shot with spaces in the name that I just shared on Dropbox with this extension:

    http://cl.ly/9FK5

    Don

  • Anonymous

    That’s so weird – it wasn’t working earlier unless I appended that parameter…and now it works fine!

    Sorry about that!

  • Anonymous

    Hi, I have tried the script for dropbox and cloud app…. It works fin, however, I think, it’s not very easy to type the entire path of the file (on the computer) in alfred window… Is there another way to enter the file path  ?

  • Anonymous

    I’m just glad it works for you!

  • Anonymous

    Yeah, you’re not suppose to type the file path. Just select the file, hit your keyboard shortcut to pull up Alfred’s Finder Selection window and choose the Share with Dropbox extension.

    If you are unsure what your keyboard shortcut is, pull up Alfred’s preferences > Features > File Navigation > and the shortcut is next to “Finder Selection”

    Don.

  • Anonymous

    Thx for your quick answer…I understand what you mean. However, I have a mac and the shortcut “alt + cmd + ” doesn’t work because I don’t have the “” caracter on keyboard…And it seems to be impossible to change in alfred settings 

  • Anonymous

    Help ???

  • Anonymous

    I’m not sure how I can help but for me, I only have to click on the keyboard shortcut to the right of “Finder Selection” and the box highlights blue, indicating that I can hit a set of keys to change that shortcut. If that doesn’t work for you, you may need to contact the developer for support.

  • Bernie

    You sir are awesome. Thanks so much!

  • spiderand

    Yeah for sure! I set up an extension using this dude’s rather awesome services http://macosxautomation.com/services/download/index.html but it presents me with a dialogue to choose image format. I preferred your PNG/JPG toggle with no dialogue.

  • Pingback: Découvrons ensemble le meilleur lanceur de l’univers : Alfred | Klakinoumi.com

  • http://jonaswouters.be Jonas Wouters

    That works (Found it first on John Gruber’s site)
    I’ve updated the scripts and made them available here: http://jns.be/ApfQ

  • http://blog.cheetahdeals.com CheetahDeals Blog

    holy moly… pretty awesome. Do you have any Alfred extensions that use mail.app, like composing a new email from Alfred?

  • Supervalpen

    Thank you for a great work. You have helped me take Alfred to a complete new level!!

    However, I am having some trouble with dropbox an cloudapp. The only thing pasted to the clipboard is “id” after I have sent the file I want to upload to dropbox.

    Screenshot: http://cl.ly/Bygs

  • Anonymous

    Thanks for letting me know! Cloudapp changed up their JSON return with API calls. I updated the extension and it works for me now. Let me know if you still have issues. Don’t for get to add your Dropbox ID and CloudApp credentials to the code.

    -Don

  • Anonymous

    This needs to be updated again. The SHARE line needs to print $15 to get the URL. It might make sense to consider switching the statement to use something like `grep -Po ‘”content_url”:.*?[^\]“,’` and splitting that. More future proof.

  • Anonymous

    I really appreciate you sharing that tip! It worked great. I updated the extension to use that grep command and gave you credits in the source.

    Thanks again,
    Don.

  • http://twitter.com/jbouie jbouie

    If I wanted to use the “Share with Dropbox” script without the CloudApp URL shortening, is there anyway I could do that?

  • http://twitter.com/VickyH101 Victoria Harazim

    Great Post! I’m a newbie to Alfred, so forgive me if this is a rookie error! I seem to be having some issues with the iOS5 Reminders extension? It creates the task, but fails to sync it to Reminders on my phone; I was wondering if you could assist me? The Growl notification works, but not the syncing, it seems

  • Jan

    Cool! Thanks for these. It seems like the amazon S3 extension may be corrupted. At least, that’s what alfred tells me when I try to open it. 

  • http://blog.code-infection.com/ Balazs Nadasdi

    API_KEY=”API_KEY”

    URL=$(curl -s https://www.googleapis.com/urlshortener/v1/url?key=${API_KEY}
      -H ‘Content-Type: application/json’
      -d ‘{“longUrl”: “{query}”}’ |
      grep -Po ‘”id”:.*’ | grep -Po ‘http[^"]*’)

    echo $URL | pbcopy
    echo $URL

    with API: http://code.google.com/apis/urlshortener/v1/getting_started.html#APIKey

    But not simpler from shell =/

  • Jay

    Adding a global hotkey to the Share with Dropbox extension breaks the script for some reason? Any guesses??

  • http://twitter.com/jeremyjaytaylor Jeremy J. Taylor

    Whenever I use the “Share on Dropbox” extension, the file moves to the public folder and appears to create a cloud URL, but the URL opens to a Dropbox (404) error. Any ideas how to resolve? Thanks!

  • Evans Thompson

    It looks like the Bit.ly extension is corrupt. Alfred won’t recognize it, and I don’t know enough about their extensions yet to troubleshoot it further.

  • Evans Thompson

    Yeah, me, too.  I haven’t taken the time to look into it further, though.

  • Anonymous

    Fixed the problem by uploading a new version, info.plist file was corrupt.

    Thanks for letting me know.

  • Anonymous

    Corrupt info.plist in this extension too… but it is fixed now.

  • Bcvc71

    Awesome extensions!  Thanks so much for sharing.  One that I love, but recently stopped working as intended is the Share With Dropbox extension.  It still moves the item to the Dropbox public folder and places the link in Cloudapp, but it no longer places a Cloudapp shortened URL in the clipboard for pasting.  Is there an easy way to fix the extension?  Thanks again!

  • Anonymous

    I updated that extension a few weeks ago so if you download it again from the provided link, it should work for you. If it doesn’t please do let me know. Also, follow @dirtdon on Twitter because I tweet from this account when I update the extensions.
    Thanks,

    Don.

  • Bcvc71

     As suggested, I downloaded it and reinstalled the extension (after
    deleting the older version), but the issue remains.  Nothing (no
    shortened URL) in the clipboard to paste.

  • Anonymous

    Ok I found what was causing the problem and fixed it. Just re-download it. I moved the code to a file “script.sh” in the extension folder (its just easier to work on that way for me because I can use an external editor).

    Thanks for letting me know!

    Don.

  • Evans Thompson

    Any chance there will be support for David Ferguson’s Extension Updater extension? (http://jdfwarrior.tumblr.com/updater)

  • Anonymous

    Yeah that is a good idea. I will do that one say soon :)


    Don Southard

  • Bcvc71

     Thanks for jumping on this!  I deleted the old extension, and re-downloaded and installed the updated one.  Unfortunately, now both the CloudApp linking and placing the shortend URL functionality appears broken. Did I miss something?  Also, your updated extension only shows ./script.sh “{query}” in the Command area of Alfred. So, even once the functionality is fixed, how can one plug in the CloudApp username and password, and the Dropbox user ID to make it all come together?

  • Anonymous

    You have to open the script.sh file and add your credentials for the extension to work. Simply right click on the Dropbox extension in Alfred’s list of extensions and choose “Show in Finder”. In that folder is a script.sh file, open it add your credentials. It should work after that.