Character id problem (bug?)

Maybe I’m going crazy, but this is really stumping me. Here is a little script that works perfectly fine on its own:

set myCharacterId to 100
set newChar to character id myCharacterId

When I use it in an Applescript studio project, it still works fine when used like this:

on clicked theObject
		set myCharacterId to 100
		set newChar to character id myCharacterId
end clicked

But as soon as I add the “tell window… - end tell” lines like so:

on clicked theObject
	tell window "main"
		set myCharacterId to 100
		set newChar to character id myCharacterId
	end tell
end clicked

I get this error message:

replacing “character id” with “unicode text id” or “string id” doesn’t work either.

However… it does work when using the deprecated “ASCII character” command:

on clicked theObject
	tell window "main"
		set myCharacterId to 100
		set newChar to ASCII character myCharacterId-- ASCII character is supposed to be deprecated since applescript 2.0
	end tell
end clicked

I’d rather not use “ASCII character” since I’m not too sure how future-proof this will make my script, it seems I have no choice though. Am I doing the right thing here?

AppleScript: 2.0.1
Browser: Safari 525.20
Operating System: Mac OS X (10.5)

Hi,

no bug!

What’s the purpose to target the window?
character id belongs to AppleScript itself and mustn’t be used in a tell block,
because unlike ASCII character there could be a terminology clash with the keyword id

These lines are actually part of a much larger script. I simplified the example to show the part where things went wrong. In the actual script, there is a reason to have it inside a tell-block, honestly :slight_smile:

I remember reading up on terminology clashes in Matt Neuburg’s book. It had something to do with using vertical bars to contain the offending command. I haven’t got the book nearby, but if that’s the solution, I’m sure I can figure it out. Thanks.

There is always a way to put those lines outside the tell block or split a large tell block into smaller parts
Anyway it’s recommended to reduce tell blocks to just the lines which should be targeted.
Alternatively use a handler, the tell block isn’t valid outside its scope


on clicked theObject
	tell window "main"
		set newChar to my getCharacterID(100)
	end tell
end clicked

on getCharacterID(ch)
	return character id ch
end getCharacterID

Yeah, I guess a few of my scripts seem to live completely inside a tell-block. Never heard of that rule of thumb before, but it makes sense.

Using the handler looks like the right way to go.

I’m just wondering, although I haven’t tried it…

A similar thing happens with text item delimiters. If you use the terms “text item delimiters” inside a tell block then it doesn’t work, but it can work if you preface it with “Applescript’s” text item delimiters. So I’m wondering if the same applies here… could you say:

Applescript’s character id?

EDIT:
I tried it in applescript and all of these scripts work so I’m confused as to the problem…

character id 65
tell application "Finder"
	character id 65
end tell
tell application "Finder"
	tell window 1
		character id 65
	end tell
end tell
tell application "Finder"
	tell window 1
		AppleScript's character id 65
	end tell
end tell

“Applescript’s character id” does the trick indeed. I didn’t know about that. Thanks a bunch.

The problem only arises when you:

1 Use it with Applescript Studio

2 Try and use a variable for the character id