Error: Expected end of line but found identifier

Can’t figure out why I’m getting this Expected end of line but found identifier error.


delay 5
use framework "Foundation"

property NSEvent : a reference to current application's NSEvent
property NSScreen : a reference to current application's NSScreen


set display to NSDeviceSize ¬
	of deviceDescription() ¬
	of item 1 ¬
	of NSScreen's screens() as record

set mouseLocation to {x, y} of (NSEvent's mouseLocation as record)
set mouseLocation's item 2 to (display's height) - (mouseLocation's item 2)

tell application "System Events" to click at the mouseLocation

set myList to mouseLocation

repeat with itemValue in myList
    set roundedValue to round itemValue
    set end of roundedList to roundedValue
end repeat

roundedList

round is part of Scripting Additions.

Add this line at the beginning

use scripting additions

thank you was frustrating… wish the error was more descriptive

It can be confusing. :slight_smile: The use scripting additions line’s only necessary because there’s another use command in the script. Were there no use commands at all, the compiler would be perfectly able to recognise round as the command from the StandardAdditions. The situation’s an AppleScript quirk.

When the compiler doesn’t recognise round as a command keyword, it assumes it’s an “identifier” (ie. variable label) and expects the line to end after that. set roundedValue to round is syntactically correct when round’s an identifier. But then there’s another identifier itemValue, which syntactically shouldn’t be there. So the compiler’s correctly reporting the error that’s occurring, but not necessarily telling you what you need to know to correct it! :grin:

The NSScreen and NSEvent classes both require the AppKit framework. The script will often work without a use framework “AppKit” statement, but it should be in the script.

BTW, doesn’t the roundedList variable need to be defined. I get an error message with the script otherwise.

1 Like