10.5: Use Automator variables anywhere in a workflow

Feb 22, '08 07:30:04AM

Contributed by: rduncan10

I used Automator in 10.5 for the first time and got quickly frustrated by the fact that you could not insert variables in many place. For example, in the Ask for Confirmation action, I could put the variable into the title, but not the message. Most annoyingly, in the Rename Finder Items action I could not use the variable to create the new file name (in my case I was using a sequential name). So I could not create a workflow that prompted the user for the filename, then use their answer to rename the files.

I searched the internet and saw some workarounds where people created shell scripts to rename the files. But I found another answer. It helps to know that that the Automator is just creating an XML file and you can edit this directly. To do this, create the Automator workflow and save it. Give the variable some distinct name like myVariable. This makes the variable easy to find.

Save the workflow and then, in Finder, right click the Automator file and select Show Package Contents from the pop-up menu. Within this folder, go to Contents and find the document.wflow file. This is the XML file, so open it with TextEdit or something.

Search the file for your variable name. The first instance of it should be in a section that starts with <key>variables</key>. All the variables will be listed here. Each variable has several lines to define it. The first will be the UUID. The UUID will have a line that is something like this:

<string>BD464B7A-ACDE-4A63-B595-FAF1DA6DE26E</string>
That long string of letters and numbers is how Automator refers to your variable. Search the file for this UUID string and you will see that whenever Automator wants to insert the variable, it will enter $(BD464B7A-ACDE-4A63-B595-FAF1DA6DE26E). Copy this string, with the $() surrounding it. Close the wflow file. Now you can go back to Automator and paste wherever wherever you want your variable to appear, even if you can't normally insert the variable into that field.

[robg adds: A commenter on the queue site tested this and said it worked perfectly.]

Comments (17)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20080213200213250