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
  • Pingback: Alfred 1.3 Improves System Navigation with “File Buffer” « The Insider View

  • Pingback: Alfred 1.3 Improves System Navigation with “File Buffer” | AVORAH - Geek Lifestyle Reviews And Views - TECH, GADGETS, STYLE.

  • http://hello-mac.net nicko

    excellent result, but not very clear what should be done. can spend in more detail?

  • Pingback: Alfred Update auf Version 1.3 bringt File Buffer, Quick Look und bessere 1Password-Integration | iEnno

  • binaryghost

    The example blocks of code explain each step of what is being done in their lines of comments. Particular the first code block is the basics of what you need to work with the multiple files passed by Alfred. This code is meant to be in a shell script file in the directory of the Alfred extension and you would call it from your Alfred extension with the line:
     ./scrip.sh “{query}” It would be easier to download the “Rename Multiple Files” extension above to see how everything works together.

    Enjoy,

    Don

  • http://alfredplus.ca/ RCS

    Wow, awesome thanks!
    RCS
    alfredplus.ca
    rcs@alfredplus:twitter .ca

  • http://philosophicalzombie.net/ Carl

    Hi there, this seems to work with multiple FILES but not FOLDERS. What do I need to do to get it to parse multiple folders? Cheers.

  • binaryghost

    Here is a link to a version that supports directories. I will update the website next chance I get.

    http://cl.ly/LpEh

    Thanks,

    Don

  • http://philosophicalzombie.net/ Carl

    Thanks Don. I’m mainly interested in how you parsed the “tab separated string” from Alfred into useable variables, and it would seem that this part of things is the same for both versions of your extension there, right?

    Cheers.

  • binaryghost

    That is correct, they are the same in that respect. It still takes the file paths passed by Alfred and puts them in to a more usable array. The only difference now is the script is checking each array item to see if it is a directory before actually renaming the item.

    Don