1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Applescript help

Discussion in 'Mac Programming' started by nfcatt, Mar 17, 2007.

  1. macrumors member

    Hi All,

    Am a newbie to AS and am having trouble trying to do what I hoped would be very easy!

    I am trying to search a text file on a line by line basis looking for a string which is midway along the line of text. Each time the string is found I need it to return the first few characters of the line it was found on and then move on checking each subsequent line until the end of the file.

    At the end of this I would like to have a variable containing all the matches.

    Any examples of how to make the loop work would be greatly appreciated!


  2. macrumors G4


    Try something like this...
    set variableStore to ""
    set sometext to "some text"
    set theparas to the paragraphs of 
    set i to 1
    repeat the count of theparas times
    [INDENT]set tp to paragraph i of sometext
    if tp contains "<search text>" then
    [INDENT]set variableStore to variableStore & "\n"& items 1 thru 5 of tp[/INDENT]
    end if
    set i to i+1[/INDENT]
    end repeat

  3. macrumors member

    Thanks, will try it out..

  4. macrumors member


    Thanks again Eraserhead, I found my error once I checked out your script..

    Was trying to do it the hard way!! - As usual...



Share This Page