How to modify (or simply retrieve) one axis of a ‘point’ data type. [type specifier error]

Hi All,

I’d like to modify one axis of a: point (type from AppleScript types suite).
It doesn’t appear to behave as a list, nor a record. I can’t even get the class of it without running into a type specifier error.

    	local xPos
    	local theClazz
    	tell application “Numbers”
    		activate
    		set thisDocument to front document
    		tell thisDocument
    			set active sheet to sheet 11
    			tell active sheet
    				repeat with imageNum from 1 to 20
    					if imageNum mod 2 is equal to 0 then
    						set xPos to rightImageXPos
    					else
    						set xPos to leftImageXPos
    					end if
    					if exists image imageNum then
    						tell image imageNum
    							set locked to false
    						    set item 1 of position to xPos -- Numbers got an error: Can’t make item 1 of position of image 1 of active sheet of document id … into type specifier.
    							set theClazz to class of position -- Numbers got an error: Can’t make class of position of image 1 of active sheet of document id … into type specifier.
    							set locked to true
    						end tell
    					else
    						exit repeat
    					end if
    				end repeat
    			end tell
    	end tell

I found a workaround… Assigning the point to a variable coerces it into a list. Perhaps a point is immutable, but it would still be interesting to know if the axes can be individually referenced!

							set currentPos to position
							set yPos to item 2 of currentPos
							set position to {xPos, yPos}

You got it. Here’s my version of the same thing:

local xPos
local theClazz
tell application "Numbers"
   activate
   set {leftImageXPos, rightImageXPos} to {30, 60}
   
   set thisDocument to front document
   tell thisDocument
      set active sheet to sheet 1
      tell active sheet
         repeat with imageNum from 1 to 4
            if imageNum mod 2 is equal to 0 then
               set xPos to rightImageXPos
            else
               set xPos to leftImageXPos
            end if
            if exists image imageNum then
               tell image imageNum
                  set locked to false
                  set imagePosition to its position
                  set positionClass to class of imagePosition
                  set item 1 of imagePosition to xPos
                  
                  set its position to imagePosition -- Numbers got an error: Can't make item 1 of position of image 1 of active sheet of document id … into type specifier.
                  set locked to true
               end tell
            else
               exit repeat
            end if
         end repeat
      end tell
   end tell
end tell

Nice! I’ve learned some new syntax there.

1 Like