View Single Post
Here's my working script

Code:
-- relayers items of the selection according to their Y (vertical) coordinate
-- select all the items you want brought to front

tell application id "OGfl"
  tell front window
    
    -- get a text list of Y coord & object ID
    set theSelection to the selection
    if theSelection is not {} then
      set theText to ""
      repeat with theItem in theSelection
        set theOrigin to origin of theItem
        set theY to item 2 of (theOrigin)
        set theID to the id of theItem
        set theText to theText & theY & tab & theID & linefeed -- use linefeed, not return!
      end repeat
      
      -- sort the text list
      set sortedIDs to paragraphs 2 through -1 of ¬
        (do shell script "echo " & quoted form of (theText) & " | sort -n | cut -f 2")
      
      -- bring each to front, in sorted sequence
      set refGraphics to (a reference to graphics of its canvas)
      repeat with theID in sortedIDs
        set oGraphic to (a reference to graphic id (theID as number))
        move oGraphic to beginning of refGraphics
      end repeat
      
    else
      beep
    end if
  end tell
end tell