My first question

Hi all !! !

Totally new !

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]

THankS a lot.

There are a lot of mistakes (apart from the wrong enclosing brackets)

  • In the display dialog expression a & is missing before high_value
  • It’s text returned rather than text return
  • It’s this_number (with underscore) rather than this number
  • It’s greater than or equal rather than greater or equal

Hi Pace514. Welcome to MacScripter.

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

Thanks guys !!!

Bad transcription on my side. I’ll get used to the english like format.

So, i dont have to put my scripts between brackets ?

see you !

Pace

Hi Pace.

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!).