Use Alfredapp (almost) as an OSX system service

NOTE: this post is outdated… a new version of it with an Alfred extension ready to be downloaded and used is here

I was trying to extend the use of Alfredapp so that it could act on the currently selected text in the frontmost application.

Here is the Custom Command I’ve come out with…. something like a text filter (it can make text UPPERCASE, lowercase, strip HTML tags, expand a Zen coding selector … etc… see below or have a look at the filter.php file for the options).

You can download the files here. See at the bottom of the article for how to configure it.

It works like this (it’s a mix of applescript and php… perhaps there are other ways to do this but it seems to work now – any suggestion is welcome):

1) You select a text  you want to modify in an application (Textedit for example)

2) You invoke Alfred and the command you have defined – I called it Filter (flt is the keyword) – like this: flt uc (where uc is the Alfredapp {query})

3) The command  gets the current content of the selection with applescript and write it to a tmp file (/tmp/paste.txt)

4) It invoke a php script (filter.php – it must be in the same folder of the command applescript) passing it the parameter (uc in this example)

5) The php script read the text from /tmp/paste.txt and apply the text transform action chosen with the parameter (uc = UPPERCASE)

6) The output from the script is copied to the clipboard with pbcopy terminal command

7) The content of the clipboard is then pasted in the frontmost application taking the place of the current selection

It works almost like a standard OSX system service and it’s easy to add new functionality to the script…

At this time it accepts the following parameters:

uc: UPPERCASE current selection
lc: lowercase current selection
uw: Uppercase All The Words In The Selection
uf: Uppercase first word
st: strip HTML tags
zc: do a ZenCoding expand of the current selection (see what ZenCoding is here)

Configuration in Alfredapp
Unpack the zip file wherever you put your Alfredapp commands (maybe you already have other ones)

Add a command to Alfredapp from the Preferences

osascript <path to where you extracted the zip>/filter.scpt {query}

I’ve named it “filter” with a “flt” keyword. Choose one you like.
Make it silent and test it.

A warning … being an applescript it’s not so speedy… so it takes a few seconds to work on my machine… your mileage may vary.

PS: the script make use of this class from Philip Walton for Zen Coding expand feature and is inspired by the works of @jdfwarrior (see http://jdfwarrior.tumblr.com/)
PPS: a big thank also to the developer of Alfredapp (@preppeller) – I always have so much fun customizing Alfred…

This entry was posted in OSX. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>