Help a noobie Find and Replace in XLC file(aka NeoOffice pref file)

I want to script the Home Folder change within a preference file for NeoOffice so that I can eliminate some work. The test document’s current path on my machine is “MacintoshHD/Users/bstage/Library/Preferences/NeoOffice-1.x/user/basic/script.xlc”. This is the same location for every user with the only change being the name on the Home folder where it resides. I want to changed a path within this XLC doc to reflect the correct Home folder. Without scripting I can open this file in TextEdit and do a Find for the text “change1” and replace it with the account Home name and then save and go along my merry way.

I want to be able to implement this over multiple user accounts so I need to take the users HOME name (shortname works too) and insert it where “change1” is located within this .XLC file. I would prefer to do this behind the GUI and it seems that a shell command would be best for this but I’m yet to find one that will actually go into the file and make the change. So far I have this, but I really don’t know enough about shell commands or AppleScript to see where I’m going wrong.

Here’s what I got. When I wun this script it makes no changes and just creates a backup of the original file which I would prefer it not too.


do shell script "file=\"$HOME/Library/Preferences/NeoOffice-1.x/user/basic/script.xlc\" ; /bin/mv \"$file\" \"$file.backup\" ; /usr/bin/sed -e 's/\"change1\"/\"'`whoami`'\"/g' \"$file.backup\" > \"$file\""

Help my feeble mind!

Browser: Firefox 1.5.0.1
Operating System: Mac OS X (10.4)

This may do the trick:

set f to (POSIX path of (path to preferences folder from user domain)) & "NeoOffice-1.x/user/basic/script.xlc"

set r to (open for access (f as POSIX file) with write permission)
set oldContents to read r
set AppleScript's text item delimiters to "change1"
set newContents to oldContents's text items
set AppleScript's text item delimiters to (do shell script "whoami")
set newContents to newContents as text
set AppleScript's text item delimiters to {""}
set eof of r to 0
write newContents to r as string
close access r

And here is the “shell” version (not an expert, so should be mistakes):

do shell script "sed s/change1/\"`whoami`\"/g ~/Library/Preferences/NeoOffice-1.x/user/basic/script.xlc > /tmp/blah.xlc; mv /tmp/blah.xlc ~/Library/Preferences/NeoOffice-1.x/user/basic/script.xlc"

The shell script works like a charm. Thanks!