Re: Should be a simple script
Re: Should be a simple script
- Subject: Re: Should be a simple script
- From: Charles Heizer <email@hidden>
- Date: Wed, 06 Dec 2000 10:53:18 -0800
I just wanted to thanks to all of you who answered my question. I built a
hybrid from Marc and Frank's examples, and it works great.
thanks again,
- Charles
on 12/5/00 4:45 PM, Marc K. Myers at email@hidden wrote:
>
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]
>
_______________________________________________
>
applescript-users mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/applescript-users