简体   繁体   English

Applescript错误“无法结束”

[英]Applescript Error “can't get end of”

I am trying my hand at Applescript and can't see anything wrong with this. 我正在尝试使用Applescript,看不到任何错误。 The Error I get is 我得到的错误是

error "Can't get end of {button returned:\\"OK\\", text returned:\\"3\\"}." 错误“无法结束{返回的按钮:\\“确定\\”,返回的文本:\\“ 3 \\”}。 number -1728 from last insertion point of {button returned:"OK", text returned:"3"} 从{按钮返回的最后一个插入点开始编号-1728:“确定”,返回的文本:“ 3”}

This is my code: 这是我的代码:

beep
set counter to 0
set tempX to 0
set temp to 0
set counting to 0
set stored to {0}
set input to "How many grades do you wish to enter?" as string
set str to display dialog input buttons {"NEXT"} default button "NEXT" default answer ""
repeat text returned of str times
    counting = counting + 1
    set grades to display dialog "GRADES:  " default answer ""
    set stored to grades
end repeat
set rep to the length of stored
repeat rep times
    counter = counter + 1
    set tempX to the ((end of stored) - counter) as number
    set temp to temp + tempX
end repeat
set ln to the length of grades
set average to temp / ln
if text returned of str is 1 then
    say "The Average of your grade is " & average using "Zarvox"
else
    say "The Average of your grades is " & average using "Zarvox"
end if
get "AVERAGE:  " & average

So, before I begin: I'd strongly recommend that you teach yourself how to use the Javascript interface to Apple Events, rather than the Applescript language itself. 因此,在我开始之前:我强烈建议您自学如何对Apple Events使用Javascript接口,而不是Applescript语言本身。 Applescript is a really weird language, and its quirks are largely unique; Applescript是一种非常奇怪的语言,其怪癖在很大程度上是独一无二的。 learning it is going to be frustrating, and won't help you learn other languages. 学习它会令人沮丧,并且不会帮助您学习其他语言。

That being said, let's dive into your code: 话虽如此,让我们深入研究您的代码:

set stored to {0}

This would start you out with one grade that's always present and set to zero. 这将使您从始终存在且设置为零的一个等级开始。 You probably want to just initialize this to an empty list: 您可能只想将其初始化为一个空列表:

set stored to {}

Next: 下一个:

set grades to display dialog "GRADES:  " default answer ""

This sets grades to a result object , not just the answer. 这将grades设置为结果对象 ,而不仅仅是答案。 What you probably want here is actually the text returned of the result: 实际上,您可能想要的是结果text returnedtext returned

set grades to text returned of (display dialog "GRADES:  " default answer "")

(This is what's creating the really weird-looking object in your error message.) (这就是在错误消息中创建看起来很奇怪的对象的原因。)


Next, you overwrite stored with this result object: 接下来,覆盖与此结果对象stored对象:

set stored to grades

What you probably want here is to insert this element into the list. 您可能想要在此处将此元素插入列表。 Because Applescript is a strange and obnoxious language, this is somewhat more cumbersome than you're thinking: 因为Applescript是一种奇怪而令人讨厌的语言,所以这比您想的要麻烦一些:

set stored to stored & {grades}

Finally, there's some logical issues with your averaging; 最后,平均有一些逻辑上的问题; you're adding the end of stored (that is, the last grade input) to the temp variable each time. 您每次都将end of storedend of stored (即最后一个成绩输入)添加到temp变量。 A much simpler approach would be: 一个更简单的方法是:

set temp to 0
repeat with n in stored
    set temp to temp + n
end repeat
set average to sum / (count of stored)

With these changes all made, your script should work correctly. 完成所有这些更改后,您的脚本应该可以正常工作。

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

相关问题 'applet中的这个“””后面不能有行尾 - 'A end of line can't go after this “”"' in this applescript AppleScript应用程序无法获得访问权限 - AppleScript application can't get rights in Accessibility 通过 Applescript 激活 Window 会引发错误,“无法获取 window 1 of process” - Getting Active Window via Applescript throws error, “Can’t get window 1 of process” 无法在 Outlook applescript 中获取传出消息的会议 - Can't get meeting of outgoing message in Outlook applescript AppleScript无法通过终端获取参数值 - AppleScript Can't Get Argument Value Through Terminal 为什么 Automator AppleScript 没有结束? - Why doesn't Automator AppleScript End? AppleScript 错误:“邮件出错:无法将文本项分隔符设置为 {”+“、”@“}。” - AppleScript error: “Mail got an error: Can’t set text item delimiters to {”+“, ”@“}.” 在Applescript中移动文件时,出现错误:“ Finder出现错误:处理程序无法处理此类的对象。” - Moving files in Applescript, got error: “Finder got an error: Handler can’t handle objects of this class.” Applescript和可可错误:预期行尾但找到标识符 - Applescript and Cocoa Error: Expected end of line but found identifier Applescript,“一个类名不能跟在这个标识符错误之后”,这是什么意思? - Applescript, “A class name can't go after this identifier error”, what does it mean?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM