1
votes

I'm trying to do the simplest thing in the world - a basic iterator in Automator. The workflow goes:

Get Value of a Variable (initially set to 1)

Run Applescript:

on run {input, parameters}
    set input to input + 1
    return input
end run

Set Value of a Variable

Loop

It works the first time, moving from 1 up to 2 as expected. But it fails on the second pass, giving the error

Can't make {} into type number. (-1700)

I'm clueless as to why - I've tried getting it to output from the Applescript as an integer and it makes no difference. Can anyone shed some light?

1
You're not showing how you loop this code so it's hard to tell where your problem is occurring, however it is easy to tell what is happening from the error. Somewhere in your loop code input is becoming a list because your error is showing you "{}". Thus on your first loop input is a number but on the second loop input is a list. So you should fix that or show more of your code so we could find the problem.regulus6633
Sorry, I'm looping it with the Automator Loop function after Set Value of a Variable. It's set to loop automatically, using the original input (this shouldn't matter as we've already redefined the variable, I think?).Nick
Same here. I just can't understand why something which should be so easy is made so difficult (impossible?). Looks like there's no solution. (Solution below doesn't work - workflow just keeps asking for user input, making the whole thing pointless)MikeyB

1 Answers

0
votes

Your error is because on the second loop of your workflow your applescript is not receiving any input. I would guess that your loop function is not receiving any input and therefore it is not passing anything back into the applescript. Whatever is between your applescript and the loop function must be interfering somehow.

As an alternative, try this as your applescript. Your automator workflow should only have 2 actions, this applescript code and the loop action set to "use current results...".

In this code, on the first loop there won't be any input to the applescript so it will ask you for input, and then on subsequent loops the applescript will receive input from the loop action and thus it will increment your initial input.

Good luck.

on run {input, parameters}
    if input is {} then
        display dialog "Enter a number" default answer "1"
        set input to (text returned of result) as number
    else
        set input to input + 1
    end if
    return input
end run