Re: Should be a simple script
Re: Should be a simple script
- Subject: Re: Should be a simple script
- From: "Marc K. Myers" <email@hidden>
- Date: Tue, 05 Dec 2000 19:45:23 -0500
- Organization: [very little]
Charles Heizer wrote:
>
Date: Tue, 05 Dec 2000 15:34:09 -0800
>
Subject: Should be a simple script
>
From: Charles Heizer <email@hidden>
>
To: <email@hidden>
>
>
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 should do the trick:
set inputFile to ((choose file with prompt "Select the input file:") as text)
tell application "Finder"
set diskName to name of startup disk
end tell
try
set fileID to (open for access file inputFile with write permission)
on error errMsg number errNbr
display dialog "File could not be opened" & return & return &
(errNbr as text) & ,
" " & errMsg buttons {"Cancel"} default button 1 with icon stop
end try
set {oldDelims, AppleScript's text item delimiters} to ,
{AppleScript's text item delimiters, {"disk1"}}
try
set theText to (read fileID)
set textList to text items of theText
set AppleScript's text item delimiters to {diskName}
set theText to (textList as text)
set eof fileID to 0
write theText to fileID
close access fileID
set AppleScript's text item delimiters to oldDelims
on error errMsg number errNbr
close access fileID
set AppleScript's text item delimiters to oldDelims
error errMsg number errNbr
end try
Marc [12/5/00 7:45:11 PM]