Applescript help

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

  1. macrumors member

    Joined:
    May 7, 2006
    #1
    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!

    Thanks,

    Nelson.
     
  2. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    Try something like this...
    Code:
    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
    variableStore
    

     
  3. thread starter macrumors member

    Joined:
    May 7, 2006
    #3
    Thanks, will try it out..

    Nelson.
     
  4. thread starter macrumors member

    Joined:
    May 7, 2006
    #4
    Hi,

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

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

    Cheers,

    Nelson.
     

Share This Page