Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.5: Use Automator variables anywhere in a workflow Apps
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.]
    •    
  • Currently 3.86 / 5
  You rated: 2 / 5 (22 votes cast)
 
[50,310 views]  

10.5: Use Automator variables anywhere in a workflow | 17 comments | Create New Account
Click here to return to the '10.5: Use Automator variables anywhere in a workflow' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Use Automator variables anywhere in a workflow
Authored by: groundswells on Mar 19, '08 05:52:37PM

Out of all the useful posts this site has this one is at the top for me. For someone with a strong shell scripting background and loving the unix pipe style of automator, this post is GREAT. Such a timesaver THANK YOU!



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: kaidoh on Apr 08, '08 12:06:11PM

Very useful hint. Thanks! I just don't understand why Automator does not allow the insertion of variables in some fields where text input is expected. Kind of cumbersome behaviour.



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: marcsmith on Jul 17, '08 11:44:26AM

Very cool hint! Thank you very much.



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: uurf on Jul 30, '08 07:53:46AM
Boy I wanted this to work, but it seems like the "Filter URLs" action still doesn't like:
Filter URL
Whose:
Entire URL contains $(D1C5DF26-7B62-46B1-AC1E-20D2A791D63F)
where $(D1C5DF26-7B62-46B1-AC1E-20D2A791D63F) is the UID for a Variable "Today's Date". Is there something unusual about the Filter URLs action?

[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: kioarthurdane on Nov 21, '08 09:06:08AM

I have the same issue with <b>Find Finder Items</b>. If you look at the results before and after the <b>Set Variable</b>, you'll see the Applescript equivalent is enclosed in curly brackets, thus it's no longer a string but a list.

I wish that I didn't have to solve all my Automator issues by just writing the whole thing in Applescript...



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: ntalect on Aug 30, '09 10:06:03AM

Do you know if this still works in 10.5.8? I've tried inserting the custom string with the $() encompassing the variable ID, but after I am prompted to enter a text value for the variable, Automator appears to quit and no further action takes place.



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: knaught on Dec 05, '09 03:09:48AM

Terrific post...thank you! A buddy and I quickly discovered the need for and inability to use variables in numerous Action fields. Why Apple doesn't provide for $(variable_name) I've no idea. But you filled the gap...bravo!

[OS X 10.6.2]



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: Kludge on Dec 07, '10 11:37:36AM

Unfortunately this doesn't work in the Make Finder Items Names Sequential with the "new name" field. Bummer.



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: who_cares on Dec 19, '10 02:17:58PM

Suggested improvement:
Edit the original UUID to something meaningful (but hopefully unused elsewhere in the script) to improve the readability of the section you wish to add the variable to.

For example,
In the section:
<key>variables</key>

Change:
<string>BD464B7A-ACDE-4A63-B595-FAF1DA6DE26E</string>
To:
<string>MY-USER-FRIENDLY-NAME</string>

Then use:
$(MY-USER-FRIENDLY-NAME)
throughout your code.




[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: clifhirtle on Mar 03, '11 09:18:40AM

Update: This works WONDERFUL even on 10.6.6. Using concept here, was able to create simple workflow app to pull the Mac's serial number and open Apple's warranty status page to check the machine's warranty/support status with zero user input. Fantastic. Thanks for posting this tip!



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: fdias on Apr 16, '11 03:11:05PM

I tested it and in some fields works correctly, but the field that exactly I need to use it, name fielder in Finder Filter, it s not working. Any one have some idea ???



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: freshnet on May 23, '11 11:54:35AM

I couldn't seem to make this work for renaming files in finder. From looking at the results it seems like the variable doesn't get filled from the 'ask for text' window. Anyone know why that could be? Or is the value of the variable not meant to show in the results?



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: killercatfish on Dec 11, '11 05:30:41PM

Hello!

I have tried to do this with the Find Finder Items and it does not work. Any advice?



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: orcus on Dec 16, '11 08:38:24AM

Running OS X 10.6.8, the techniques mentioned in this hint successfully helped me produce an automated Entourage message (using the Entourage Automator actions) using variables in the 'subject' text field of the 'New Entourage Message' action, which by default does not support use of drag-and-drop automator variables.

This included the built-in 'current month', as well as a custom variable whose value is generated by an applescript at runtime. I copy and pasted the key values with dollar sign and parentheses i.e. "$(A9039CA2-DD28-4F04-B9BE-AA89193A1099)" as outlined in the hint into the subject line and lo, it worked! Very nifty, useful hack.



[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: djolsen on Aug 20, '12 07:59:41PM

This no longer works in Mountain Lion. Has anyone had success inserting string values into workflows in ML? I have a script to insert these values into an email but it no longer works in ML



[ Reply to This | # ]
How to still get this to work in Mountain Lion
Authored by: trencherjr on Oct 23, '13 01:03:43PM
This no longer works to embed variables in the body of an email created with the "New Mail Message" action in Automator (I had it working in 10.6.8, but no go in Mountain Lion as was reported). However, embedding variables in this way still works in Applescripts called via the "Run Applescript" action in Automator. Something like this works:
on run
	tell application "Mail"
		set newMessage to make new outgoing message with properties {subject:"Meeting with $(34BB10BD-7F75-4871-A89F-8252F1FF251A)", content:"Dear $(E6B1894A-A0DE-4BF1-907A-B66561D9C4BD)..." & return & return}
		tell newMessage
			set visible to true
			make new to recipient at end of to recipients with properties {address:"$(67EC9CB4-D3FB-41D8-9782-835E792DF9B9)"}
		end tell
		activate
	end tell
end run
This method still seems to work with certain actions but not with others.

[ Reply to This | # ]
10.5: Use Automator variables anywhere in a workflow
Authored by: dbuchter on Oct 25, '13 12:10:02PM

I know the title is 10.5, but I just wanted to add that some of these variables are still not working in 10.9 (Mavericks) such as the adding Today's Date to the message body of an email. Why isn't Apple updating Automator?



[ Reply to This | # ]