3 Replies Latest reply: Apr 25, 2007 7:38 AM by JSAF
noeqplease Level 4 Level 4 (3,580 points)
Hi,

I wanted to know if this can be done using Automator to replace text inside a file - and batch processing it.

I have over 1750 files that need the same exact word replaced on every one.They are "preset" files for Logic Pro.They are now pointing in the wrong directory username,and I just need to place my username there instead,so the presets work.

The text to be replaced is always the same,and the text to replace with is also the same.I would like it to be a batch process, i.e. I tell Automator the folder/files and it will "automatically" do it.

I tried with scripting,and it's too complicated to even get a file open.And with autoomator...I'm hopeless!!! I could not even figure out how to use the stock actions...I read the manual from top to bottm...but it escapes me how to get it to run,after making a test action.I save the action,and then.....WHAT???

Otherwise I'll have to make all 1750 presets new from scratch...and I'm not about to do that.

Thanks in advance for any help.

Cheers

Caffeine Ultra/Expresso Cards/No Foam, Mac OS X (10.4.8), Wooden Club 1.2/Staffordshire 7.2.3/1902 Horse drawn Cart
  • 1. Re: Using Automator to replace text inside a file - and batch processing it
    Glen Doggett Level 4 Level 4 (1,795 points)
    Yes, it can be done. But not necessarily with Automator alone, you need a tool that can actually process the files, I think Automator is more like a linking framework that links inputs and outputs from different tools and apps together into a workflow, rather than doing any of those detailed tasks itself.

    I am not that experienced with AutoMator and AppleScript, but they can be used to select a bunch of files and perform an action on those files, maybe someone can help out with that part.

    The basic job you need to perform can be done with the UNIX stream editor, /usr/bin/sed, with a command something like this:

    /usr/bin/sed -e 's/oldpath/newpath/g' oldfile > newfile

    This will replace all occurences of "oldpath" with "newpath" in the file: oldfile and write the results to the file "newfile"

    This could be done in a UNIX script that you run in the Terminal command line, or packaged into an Apple Script that you write in Script Editor.

    I hope this helps, and someone else can add some finishing touches or recommend a better approach.
  • 2. Re: Using Automator to replace text inside a file - and batch processing it
    noeqplease Level 4 Level 4 (3,580 points)
    No one answered it.

    Back to teh drawing board...
  • 3. Re: Using Automator to replace text inside a file - and batch processing it
    JSAF Level 1 Level 1 (10 points)
    I am getting into using Unix through Terminal and found this really helpful, thanks Glen. l wanted to create a bit of 'script' to find and replace a series of pieces of text in a text file. Cheers, James