Use Alfred (almost) as an OSX Service (UPDATED)

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 extension 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 in the extension for the options).

You can download the extension here.

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 extension downloaded – 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) – issuing a CMD – C with applescript

4) It invoke a php script 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 (mainly usefull for web developers… see what ZenCoding is here)

This is a version of the script packed as an Alfred extension… (I made some time ago another one (before Alfred could import/esport extensions) but it is replaced by this)

A warning … being an applescript it’s not so speedy… so it takes some time 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

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>