sashaosonia

Q: pass text as string applescript

Hello everybody,

I trying to write apple script and now script returns me results as "11,22,33" as a text

how can I convert it to string {11,22,33}

 

solution with "item 1", "item 2",, etc doesn't work because sometimes 11 can be 111 or just 1. The same with another numbers. I think that script must understand than comma marks new number but I do not know how it do

MacBook Pro, OS X El Capitan (10.11.2), null

Posted on Jul 4, 2016 9:22 AM

Close

Q: pass text as string applescript

  • All replies
  • Helpful answers

  • by stevejobsfan0123,Apple recommended

    stevejobsfan0123 stevejobsfan0123 Jul 4, 2016 9:45 AM in response to sashaosonia
    Level 8 (43,703 points)
    iPhone
    Jul 4, 2016 9:45 AM in response to sashaosonia

    sashaosonia wrote:

     

    I think that script must understand than comma marks new number but I do not know how it do

      set AppleScript's text item delimiters to ","
      set someText to someText's text items
      set AppleScript's text item delimiters to {""}
    
    
    

     

    Replace "someText" with the variable name you created which holds the text result.

  • by sashaosonia,

    sashaosonia sashaosonia Jul 4, 2016 9:45 AM in response to stevejobsfan0123
    Level 1 (8 points)
    Mac OS X
    Jul 4, 2016 9:45 AM in response to stevejobsfan0123

    got it!

     

    new word to me - 'text item"

    Thanks a lot

  • by stevejobsfan0123,

    stevejobsfan0123 stevejobsfan0123 Jul 4, 2016 9:47 AM in response to sashaosonia
    Level 8 (43,703 points)
    iPhone
    Jul 4, 2016 9:47 AM in response to sashaosonia

    You're welcome.

  • by Camelot,Solvedanswer

    Camelot Camelot Jul 5, 2016 7:11 PM in response to sashaosonia
    Level 8 (47,285 points)
    Mac OS X
    Jul 5, 2016 7:11 PM in response to sashaosonia

    'text item' works in conjunction with 'text item delimiters' to break a text object into discrete items.

     

    Ordinarily the text item delimiters is an empty string, which has theeffect of breaking a text object into individual characters:

     

    text items of "1,2,3,4"

    --> {"1", ",", "2", ",", "3", ",", "4"}

     

    Adding a text item delimiter gives you the ability to break the text on any given character:

     

    set my text item delimiters to ","

    text items of "1,2,3,4"

    --> {"1", "2", "3", "4"}

     

    You're not limited to single character delimiters, either:

     

    set my text item delimiters to "the"

    text items of "the quick brown fox jumped over the lazy dog"

    --> {"", " quick brown fox jumped over ", " lazy dog"}

     

    or even single delimiters:

     

    set my text item delimiters to {"a", "e", "i", "o", "u"}

    text items of "the quick brown fox jumped over the lazy dog"

    --> {"th", " q", "", "ck br", "wn f", "x j", "mp", "d ", "v", "r th", " l", "zy d", "g"}

     

    In short, any string, or list of strings, can be used to delimit any text object.

     

    Just be aware that any change in delimiters is retained throughout your script, so it's best to save the current state, delimit your string, then reset the delimiters to avoid confusion later on when the delimiters aren't what you expect:

     

    set oldTID to my text item delimiters --> save the current TID

    set my text item delimiters to "," --> set your new TID

    set myList to text items of "123,45,678,90" --> delimit the string

    set my text item delimiters to oldTID --> and restore the original TID