I d’ont know if if i’m doing it right but you’ll tell me…
Here’s a script from Sal Sagohian’s book.
I’d like to know why it is not compiling ?
[set low_value to 1
set high_value to 10
repeat
display dialog (“Enter a number between”)¬
& low_value & " and " high_value & “:” default answer “”
try
if the text return of the result is not “” then¬
set this_number to¬
the text return of the result as number
if this number is greater or equal to low_value and¬
this number is less than or equal to high_value then
exit repeat
end if
on error
beep
end try
end repeat]
When posting here, would you mind giving your posts more descriptive subject lines? Here it could be something like “Script won’t compile”.
There are a number of copying errors in the code you posted. I imagine it should look like this:
set low_value to 1
set high_value to 10
repeat
display dialog ("Enter a number between") ¬
& low_value & " and " & high_value & ":" default answer ""
try
if the text returned of the result is not "" then ¬
set this_number to ¬
the text returned of the result as number
if this_number is greater than or equal to low_value and ¬
this_number is less than or equal to high_value then
exit repeat
end if
on error
beep
end try
end repeat
However, from the point of view of not using the ‘result’ more than once and not getting the ‘text returned’ value from it more than once, it would be better like this:
set low_value to 1
set high_value to 10
repeat
set this_number to text returned of (display dialog ("Enter a number between") ¬
& low_value & " and " & high_value & ":" default answer "")
if this_number is not "" then
try
set this_number to this_number as number
if this_number is greater than or equal to low_value and ¬
this_number is less than or equal to high_value then
exit repeat
end if
on error
beep
end try
end if
end repeat
Not in the scripts themselves. When posting scripts to MacScripter, we have special [applescript] and [/applescript] tags which make them appear as above: in boxes with clickable links which open them in an editor. AppleScript code should be enclosed between these when it’s posted here.
AppleScript uses (), {}, and «» brackets for various purposes, but [] brackets shouldn’t be used at all in scripts (unless they’re required in text, of course!).