Re: Should be a simple script
Re: Should be a simple script
- Subject: Re: Should be a simple script
- From: Michelle Steiner <email@hidden>
- Date: Tue, 5 Dec 2000 16:25:19 -0800
On 12/5/00 3:34 PM, Charles Heizer <email@hidden> wrote
>
I think I'm going to shoot my self, I've been doing Unix stuff to long.
>
>
I need a simple script to edit the contents of a Text file. I will have a
>
file in "My Hard Drive:System Folder:Prefrences:My Settings.txt" that needs
>
to replace the Word "Disk1" with what ever the hard drive name is of the
>
current system.
>
>
In unix this is easy with sed and awk, but I can't seem to remember how
>
using Applescript.
>
>
Please help!
This will do it; I assume that someone else will come up with something
more elegant.
--Michelle
set OldName to "disk1"
tell application "Finder"
set foldername to path to preferences folder as alias
set DiskName to name of the startup disk
end tell
set theFile to ((foldername as text) & "My Settings.txt") as alias
open for access theFile with write permission
set theData to read theFile
set theoffset to offset of OldName in theData
set part1 to text 1 through (theoffset - 1) of theData
set part2 to text (theoffset + (count (OldName))) through -1 of theData
set theData to part1 & DiskName & part2
write theData to theFile starting at 1
close access theFile
----------------------------------------------------------------------
| Michelle Steiner | Hard as it may be to believe, my |
| email@hidden | life has been based on a true story. |
----------------------------------------------------------------------