Re: Should be a simple script
Re: Should be a simple script
- Subject: Re: Should be a simple script
- From: Frank Watzl <email@hidden>
- Date: Wed, 6 Dec 2000 01:37:19 +0100
At 15:34 Uhr -0800 05.12.2000, Charles Heizer wrote:
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.
This might help:
[It will not only change "foo disk1 bar" to "foo name-of-disk bar"
but also "foo disk1's size bar" to "foo name-of-disk's size bar".]
tell application "Finder"
set DiskName to name of startup disk
end tell
set myFile to (choose file with prompt "Select Preferences File to update")
tell AppleScript
set oldDels to text item delimiters
set text item delimiters to {"disk1"}
end tell
set myOpenFile to open for access myFile with write permission
try
set itemList to text items of (read myOpenFile)
tell AppleScript
set text item delimiters to {DiskName}
end tell
set newtext to itemList as string
write newtext to myOpenFile starting at 1
tell AppleScript
set text item delimiters to oldDels
end tell
set eof myOpenFile to count of newtext
close access myOpenFile
on error
close access myOpenFile
display dialog ("error while updating " & myFile as string) & " ."
end try
Frank Watzl
Frankfurt am Main, Germany