alexanderPL

Q: applescript save text from results view

Hello, I working with applescript which takes results in to bottom window of editor, like this

 

1.png

Now I attempt to write it in the text editor as a text but Applescript tell that it can't with "Can not turn "class piPt to text"

2.png

 

and if I try save results as list, applescript takes mistake 10000 (textEdit received an error: AppleEvent failure in popup written)

 

3.png

Is anybody knew how can I fix it?

MacBook Air, OS X Yosemite (10.10.3)

Posted on Jun 25, 2016 12:00 PM

Close

Q: applescript save text from results view

  • All replies
  • Helpful answers

  • by alexanderPL,

    alexanderPL alexanderPL Jun 25, 2016 12:03 PM in response to alexanderPL
    Level 1 (8 points)
    Mac OS X
    Jun 25, 2016 12:03 PM in response to alexanderPL

    here is script text, but it will not be work at yours mac because it use Imagine Photo application/

     

    set thisFile to choose file with prompt "Choose an image file: "

    tell application "iMagine Photo"

      set thisImporter to import graphic thisFile

      if the component error of thisImporter is not equal to 0 then

      close thisImporter

      display dialog "Not an image file that quicktime recognizes."

      return

      end if

      set {x, y, xDim, yDim} to the natural bounds of thisImporter

      set thisDocument to make new window document with properties {dimensions:{xDim, yDim}}

      set the drawing destination of thisImporter to thisDocument

    draw thisImporter

    close thisImporter

    -- The following section is to be replaced depending on the pixel value class

      set pixelValueRect to {x, y, xDim, yDim}

      set pixelValues1 to get pixel values of thisDocument with properties {pixel value class:pixels in rectangle, bounds rectangle:pixelValueRect}

    close thisDocument

    --class (pixel points) as list

    --"class pCol" as list -- цвета и координаты разнесены по классам с именами, приводим к списку

     

    end tell

    tell application "TextEdit"

    activate

    make new document

      set text of document 1 to pixelValues1 as list

    -- set text of document 1 to pixelValues1 as list

    -- save document 1 in "/Users/IMac/Desktop/LastUpdate.txt"

    end tell

    pixelValues1

     

  • by Hiroto,Helpful

    Hiroto Hiroto Jun 25, 2016 12:45 PM in response to alexanderPL
    Level 5 (7,286 points)
    Jun 25, 2016 12:45 PM in response to alexanderPL

    Hello

     

    If I understand correctly, you're trying to coerce an AppleScript record to text. Unfortunately record-as-text coercion is not supported in AppleScript language. Fortunately there's been workaround to extract text representation of any AppleScript object from error string, which is ugly but works.

     

    E.g.,

     

    set x to {list:{0, 1, 2, 3}}
    --return x as string --> error -1700
    return to_s(x) --> "{list:{0, 1, 2, 3}}"
    
    on to_s(a)
        (*
            a: anything
            return Unicode text: text representation of a
        *)
        local astid0
        set astid0 to AppleScript's text item delimiters
        try
            {«class AAAA»:a}'s «class BBBB»
        on error t --  t = "Can't get «class BBBB» of {«class AAAA»:a}"
            try
                set AppleScript's text item delimiters to {"{«class AAAA»:"}
                set t to t's text items 2 thru -1 as Unicode text
                set AppleScript's text item delimiters to {"}"}
                set t to t's text items 1 thru -2 as Unicode text
                set AppleScript's text item delimiters to astid0
                return t -- t = a, which is in Unicode text
            on error errs number errn
                set AppleScript's text item delimiters to astid0
                error errs number errn
            end try
        end try
    end to_s
    

     

     

     

    For your specific case, you may try something like this:

     

     

    tell application "iMagine Photo"
    
        -- set pixelValues1 to ...
        
        set t to my to_s(pixelValues1)
    end tell
    
    tell application "TextEdit"
        tell (make new document)
            set its text to t
        end tell
    end tell
    
    on to_s(a)
        (*
            a: anything
            return Unicode text: text representation of a
        *)
        local astid0
        set astid0 to AppleScript's text item delimiters
        try
            {«class AAAA»:a}'s «class BBBB»
        on error t --  t = "Can't get «class BBBB» of {«class AAAA»:a}"
            try
                set AppleScript's text item delimiters to {"{«class AAAA»:"}
                set t to t's text items 2 thru -1 as Unicode text
                set AppleScript's text item delimiters to {"}"}
                set t to t's text items 1 thru -2 as Unicode text
                set AppleScript's text item delimiters to astid0
                return t -- t = a, which is in Unicode text
            on error errs number errn
                set AppleScript's text item delimiters to astid0
                error errs number errn
            end try
        end try
    end to_s
    

     

     

    Good luck,

    H

  • by alexanderPL,

    alexanderPL alexanderPL Jun 25, 2016 12:45 PM in response to Hiroto
    Level 1 (8 points)
    Mac OS X
    Jun 25, 2016 12:45 PM in response to Hiroto

    Thanks! It works!

    Can texedit app do with this text additionally? e.q. write it in the some rules (five numbers in string, for example)