Setting a repeat value on the fly with a variable…not possible?

I have a macro in Mail that I want to run through a folder of emails and saves them to a PDF after I give them a title. I would like to have the ability to enter a repeat value for the repeat using a variable because the number of emails in the Folder will vary each time I do it and I could manually enter this myself or use and applescript to get the number of emails in the folder. But if I save a number in a variable and then try to enter the variable in the field for the 'repeat' macro step (which seems to default to a number with up and down arrows), it errors out. The initial email is selected in Mail and when it is done processing, the email is deleted and the next one is automatically selected so this proccess can keep going until I am through the entire folder.

Any other approaches to repeating something which is not a set value that allows a variable to set the number of repeats? ("For Each" also seems to want numbers even if you select a "number range")



You can definitely put a Variable in this field. I do it all the time. Enter the Variable without the % signs each side as this is a Numeric Field (it expects a number) rather than a Text Field (which expects text and so needs the % to tell the text is a Variable or Token).

The clue is that fields that expect Text have a little "T" in them.

So, put the Variable into the Field in the Repeat Action like this (without the % signs).


1 Like

@Zabobon showed you that the field may contain a "T". When you see a T, the contents of the field are treated as text UNLESS you include percentage marks which allow you to insert a calculation, variable or even a dictionary. Here are three examples of these choices. I draw your attention to the "T" using the red arrows. This illustrates that in a Text field you can insert text OR variables OR numeric calculations.




You could even combine text, variables and expressions into a single field, perhaps like this:

If the field contains a "C" then the contents are treated as a numeric expression and you can use variables there directly without using percentage marks. Here's one example where an expression is used that includes a variable:

If the field contains a "V" then the contents must be a variable name and nothing else. Here's an example:


If the field doesn't contain a T, C or V, then (I think) it's a plain text field that doesn't support percentage marks. Those are pretty rare. Here's an example in the "title bar comment field" for a macro. Notice the lack of a T, C or V in the field:

Even though I'm used to all these things by now, I slip up a couple of times per year, typically when I forget I'm in a "C" field and I start entering "%" marks for variables.