Newbie requiring help...

Thanks for reading this!

I’m making an installer using StuffitInstallerMaker 7.1.1. part of the installation requires that i modify text within a text file (i’m installing a modification for Deus Ex, and it requires you to change 3 lines of text within deusex.ini - a text file). i see from apple’s website that neither textedit nor simpletext are scriptable. i’d like to write a hybrid os9/x script that would be able to change these lines of text within the file. how can i do that without requiring the user to install additional software? thanks a ton…

-blobbo

If by “textedit” you mean “Tex-Edit Plus” then there is a misunderstanding somewhere. It is THE scriptable word processor par exellence.

um, can someone help me with my initial question? i’ll try out textedit plus for sure :). but i really need help with the initial post…

Well, since it turns out Textedit is scriptable, you could use that to edit text on the end-user’s machine.

Or, you could do it w/ just AS. The following example is a script from Marc Myers. It reads chunks to the end of the file, which is not really what you want to do, but it’ll give you a start. See the File Read/Write section of the Standard Additions dictionary for more info.

set theFile to (choose file)
set fileID to (open for access theFile)

try
    repeat
        set theText to (read theFile before return)
        log theText
    end repeat
on error m number n
    close access fileID
    if n is not -39 then -- if so, then EOF
        display dialog (n as text) & return & m
    end if
end try

–tet

Marc, if you read this…

Fascinating piece of code. I sense there’s something to learn here. What did you write it for? What does it do - or should I ask rather what one does with it - with the line after line appearing in the log?

An explanation from you would be very welcome.

See below link for the original post (see rest of the thread for the context.)

–tet

Aha! Not as esoteric as I’d thought it might be - actually pretty simple - but, of course, nice to-the-point code from The Man in Green!

Thank you, tet.

like this:

-- set this to the start of where you want to change things (one before the first character to change)
set startOffset to 10
-- set this to the end (one after the last char to change)
set endOffset to 15
-- set this to what to change it to
set newText to "blah blah" & return & "more text"
-- get file to change
set f to choose file
-- read file
set df to open for access f
try
set t to read df
on error m number n
close access df
error m number n
end
close access df
-- change text
set newT text 1 through startOffset of t set newT to newT & newText
set newT to newT & text endOffset of t
-- write changes
set df to open for access f with write permission
try
set t to write newT to df
on error m number n
close access df
error m number n
end
close access df
-- done

i havn’t tested it, sorry i don’t have time. email me if it doesn’t work - jail