简体   繁体   English

简单的Apple Automator迭代器不起作用(使用AppleScript)-为什么?

[英]Simple Apple Automator iterator not working (using AppleScript) - why?

I'm trying to do the simplest thing in the world - a basic iterator in Automator. 我正在尝试做世界上最简单的事情-Automator中的基本迭代器。 The workflow goes: 工作流程如下:

Get Value of a Variable (initially set to 1) 获取变量的值(最初设置为1)

Run Applescript: 运行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. 它第一次工作,从1升至预期的2。 But it fails on the second pass, giving the error 但是它在第二遍失败,给出了错误

Can't make {} into type number. 无法将{}设为类型编号。 (-1700) (-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. 关于原因,我一无所知-我试图将其作为整数从Applescript输出,但没有区别。 Can anyone shed some light? 谁能阐明一些想法?

Your error is because on the second loop of your workflow your applescript is not receiving any input. 您的错误是因为在工作流的第二个循环中,您的applescript没有收到任何输入。 I would guess that your loop function is not receiving any input and therefore it is not passing anything back into the applescript. 我猜想您的循环函数没有收到任何输入,因此没有将任何内容传回applescript。 Whatever is between your applescript and the loop function must be interfering somehow. applescript和循环函数之间的任何内容都必须以某种方式进行干扰。

As an alternative, try this as your applescript. 或者,尝试将其作为您的applescript。 Your automator workflow should only have 2 actions, this applescript code and the loop action set to "use current results...". 您的自动化程序工作流应仅包含2个操作,此applescript代码和循环操作设置为“使用当前结果...”。

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. 在此代码中,在第一个循环中,applescript不会有任何输入,因此它将要求您输入,然后在随后的循环中,applescript将从循环操作中接收输入,因此它将增加您的初始输入。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM