Selection as point

(Jonas Whale) #1

When I try to get the selection in a script window, if the location is greater than 32767, I get this error:

Impossible de convertir {32768, 20} en type point.

This happens only if the reference to the script document is set into a variable. Like this:

set activeDoc to document 1 -- or script window 1
set selection of activeDoc to {32768, 20}
selection of activeDoc as point

This works fine:

set selection of document 1 to {32768, 20}
selection of document 1 as point

And that too (which I use as a workaround):

set docNum to 2
set selection of document docNum to {32768, 20}
selection of document docNum as point

MacOS 10.12.6 (16G1314)
Script Debugger 7.0.2 (7A51)
Script Debugger 6.0.8 (6A225)

(Shane Stanley) #2

Interesting. You’re first example is a simple coercion, equivalent to:

{32768, 20} as point

And it looks like the AppleScript point is is pretty limited in range.

The latter two examples work because they behave more as parameters — Script Debugger produces the result.

I prefer to use none of these, but rather to ask for the property I want:

	character range of selection of activeDoc

(Jonas Whale) #3

Do you think it’s a reminiscence of times where Applescript was 16 bit?

Thanks for reminding me this. :wink:

(Nigel Garvey) #4

… and before QuickDraw was deprecated thirteen years ago. :wink:

(Shane Stanley) #5

I don’t think anything Mac was ever less than 32-bit, but I presume it was a case of using a 32-bit struct to store two 16-bit values. These were designed for screen coordinates, so that would have been seen as plenty big enough.

(Thomas Tempelmann) #6

Many values were indeed stored in (often signed) 16 bit types, like this Point type for screen coordinates. This comes from the pre-OSX times, when memory was still precious and saving a few bytes made a difference. Applescript still uses those old types in many places for standard types like this Point type, it seems.

The modern NSRect and NSPoint types from OSX (Cocoa) use floating point types (using 4 bytes in 32 bit apps and 8 bytes in 64 bit apps). Maybe you could change your script to using NSPoint types, though that would only work if the scripted app also uses those types internally and is prepared to accept them. Probably not.

(Jonas Whale) #7

That’s not necessary here: my confusion was that as point was not returning the same result as usual.
Shane leads me to the problem: when puting the document in a variable, as point is no more the command from SD but the one from AS.
But we are lucky, SD has a second method to retrieve the selection!

When working on strings outside of applications that are able to manage large texts, I’m always using asoc.

And if I remember well, there was a time where compiled scripts were limited in size (e.g. System 7).