How to Implement Multi-File Actions in Alfred 1.3

I wanted to write up a quick post on how I implement multi-file actions in Alfred 1.3 so you can get a better idea on how to use the new feature and hopefully use this to start making your own multi-file extensions.

My language of choice, as usual, is bash; however the concept is the same in any language. Alfred provides your extension with a tab delimited string of files that you parse and perform actions on.

Example:


The code above is a basic implementation in bash that parses the input by tabs and puts each file in to an array. Then iterates through the array and does something with each file. The only line worth specifically noting is the line:

 IFS=$'\t' 

Even though tabs are already apart of the default IFS (input field separators) along with spaces and newlines – I have overwritten the IFS to consist of only tabs so that filenames with spaces don’t break up in to multiple items in the array.

Here is a full blown example implementation in an Alfred shell script extension that is designed to accept multiple files and batch rename the files based on a prefix supplied by the user. A download link for the extension is provided at the end of the post. [1]


*Note: In order for this extension to accept multiple files, it is required to check the new option in the extension’s settings: “Accept multiple files as argument”

To wrap this up, here is a video of the extension in action:


  1. Alfred Extension Download Link: Rename Multiple Files

A Script For Scripting A Script

I make a lot of scripts. I have scripts intended for long term management of tasks and files. I have made short term scripts, or single-use scripts to batch manipulate a directory of files in some custom manner. I have scripts that run at launch and other scripts to interact and automate the gathering of information from web based services.

It occurred to me that I had never automated the process of making a script.

I know there is not much to starting a new script, but thats not really the point of automation. It is simply about reducing the amount of un-necessary repetition in your workflow. I realized that when I start a new script its almost always a shell script, almost always on the desktop, and there is almost always the same bit of text inside the script to get me started.

Here is an example of my own boiler-plate shell script:

Not much to it, but it is a great starting point. You are probably wondering why I have an empty main function even though it does not offer much in the way functionality. I find it beneficial to break up shell scripts in to functions for increased readability as well as code re-usability. A well written shell function can be copied and pasted in to any other future scripts without having to change much code.

Lets take a look at the code to generate this script:

You will probably want to update the NAME variable so that it reflects your own name. You don’t have to change the DIR variable unless you want your scripts to go some where other than your desktop. The script creates the file on the desktop, generates the boiler-plate content, sets executable permissions on the script, then opens it in your default text editor.

I should note that you do have the ability to set a filename when creating a new script. The IF/ELSE statement at the end of this code checks to see if you have sent it a filename, if it does not find one it simply names it script.sh. You do not need to type out the .sh extension because it is automatically added for you in the script. Also, don’t use spaces in your script filenames.

I use this script in conjunction with an Alfred extension for optimal productivity. I am attaching the extension below so feel free to download and try it out.

I simply launch Alfred and type either script or script someFilename

If shell scripts aren’t your thing, this script could be easily adapted to whatever scripting language you prefer. If you need any help modifying it, just let me know and I will do my best to help you out.

Enjoy

Download


Start a new script extension

Create a Simple Cork Texture in Pixelmator

  • Fill with a brown color. I used #7f5024

  • Add noise. Filter > Stylize > Noise…
  • Amount: 25
  • Monochrome checked

Quickly Add Files to OmniFocus with Alfred

Have you ever created a task in OmniFocus that needed a file attached? Sure you have and there are a million different ways to make that happen. But how do you track down the file that you need? I instinctively rely on Alfred because it is the path of least resistance. Alfred will find that file in any directory as fast as I can type, so why not use Alfred to send that file to OmniFocus?

This Alfred extension is intended to be used as an Action and lets you send a file to whatever task is currently selected in OmniFocus. It will even ask you if want to embed the file or just create and alias to the file and add that to the task.

Download the extension here: Send File to OmniFocus

Only tested on Mac OS X Lion (current version) and OmniFocus on MAS (current version)

 

Now enjoy some action shots!


File embed choice:


Result:


Enjoy!

Authenticate for Alfred


 It solves the problem of storing plaintext credentials inside Alfred extensions.

Check out Authenticate

watermarker-ad
thumbtack

Archives