applescript repeat until end of file/document

Discussion in 'Mac Programming' started by travman1974, Jan 1, 2011.

  1. travman1974 macrumors newbie

    Joined:
    Jul 9, 2009
    #1
    Is there a way to repeat an apple script until it reaches the end of the file or document.

    I am trying to use applescript with text wangler to manipulate an qfx file to work with my quicken. Basicly I need to have the <NAME> field be less than 32 characters or my quicken will error out. I have the following code wich works for what I need.

    Code:
    tell application "TextWrangler"
    	activate
    		find "<NAME>................................" searching in text 1 of text document 1 options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false} with selecting match
    		copy selection
    		find "$" searching in text 1 of text document 1 options {search mode:grep, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:true} with selecting match
    		delete selection
    		paste
    	save text document 1
    end tell
    the code works for what I need, but I can't figure out how to get it to repeat for the entire file. Each time I download a qfx file from my bank the size of the file will change. how can I get the repeat function to work until the end of the file or document.

    Thanks
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    As i found out in http://forums.macrumors.com/showthread.php?t=1069132 Applescript does offer more traditional file access routines that might allow you to skip using TextWrangler.

    This also seems like a great project for Perl.

    B
     
  3. andy 111r macrumors newbie

    andy 111r

    Joined:
    Nov 13, 2010
    Location:
    leeds
    #3
    You don't need to write a script for this you can do it textwrangler with grep.

    Just go to the find option and put in the following in the find box.

    (?<=<name>................................).*?(?=$)

    Then choose replace all.

    That will find every line starting with <name> and strip off the end of the line after the 32nd character.

    You can then save the find in textwrangler to repeat at your leisure.
     
  4. travman1974 thread starter macrumors newbie

    Joined:
    Jul 9, 2009
    #4
    Thanks soo much that worked perfectly. I knew there had to be a way to do it using grep.

     

Share This Page