Big crisis!! Plus file managment and editing.
Big crisis!! Plus file managment and editing.
- Subject: Big crisis!! Plus file managment and editing.
- From: "Nico Christie" <email@hidden>
- Date: Mon, 24 Nov 2003 17:34:10 -0300
Hi everyone! I have a mayor crisis going on!! Somehow, I managed to save
one of my scripts as an application, losing all of the code I had written
(on which I've been working for months already). I remember having read
something about the Terminal (which I know nothing about) and getting code,
or handlers through it. I was wondering if anyone has suggestions on what
to do.
In other areas, I have this "handler for reading lines" already written:
(* This handler reads line "line_to_read" from file "Path_to_file".
A line is considered if it ends in 'Carriage Return' .*)
to read_line(Path_to_file, line_to_read)
set Prev_delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to CR
set the_data to text items of (read Path_to_file from 1 to eof)
try
set The_Return to (item line_to_read of the_data)
on error
set The_Return to 0
end try
set AppleScript's text item delimiters to Prev_delim -- this MUST be executed,
or else mayor crash in afterwards processes.
return The_Return
end read_line
I'd like one for "writing lines". I started one with exactly the same code
as above but changing the try a little, but realized some problems came
up if the replacement line is shorter than the older one, and when I wanted
to re-write the changed data to the file, some of the old data was left
on the file (the last characters)
(* This handler should replace the line 'line' of a file (given it's path)
with 'info'. Again, line is considered if it ends in 'Carriage Return' .*)
to write_line(Path_to_file, line, info)
...
try
set (item line of data_as_list) to info
on error err_msg
set (item line of data_as_list) to ""
end try
my Save_Log(Path_to_file, data_as_list as string, 1)
...
end write_line
where 'Save_Log' would be: (I'm just adding this one because 'write_line'
uses it and because I'd like to now if I'm doing something terrible here
I never noticed...)
(* This handler writes 'some_data' to a file (recieves it's path) starting
at 'where'. It does not care if it is overwriting text already written before.
*)
on Save_Log(Path_to_file, some_data, where) -- 'where' would be where it
will start writing from: eof, 1, 23, 50, -1. -123, etc.
try
try
set where to (where as integer) -- could be 'eof', not a valid integer,
but could be 'donkey' too.
-- on error
-- set where to eof -- (Should I? If it was 'donkey', no changes will
be made to 'where', so nothing will happen and first 'try' will crash too.)
end try
set Path_to_file to Path_to_file as alias -- to prevent from creating
a file (that should be taken care of somewhere else)
open for access Path_to_file with write permission
write some_data to Path_to_file starting at where
close access Path_to_file
on error
try
close access Path_to_file
end try
end try
end Save_Log
Ok, thanks a lot. I hope to get good news. (and/or comments on any other
things I wrote)
Nikel
(newest and now biggest fan of backing up)
PS: Sorry, it got a bit long...
Nicolas Christie
email@hidden
email@hidden
--------
E-mail y acceso a Internet UltraVeloz totalmente GRATIS en Buenos Aires,
Rosario, Cordoba, Mendoza, La Plata y Pilar
http://www.Argentina.com
Nro. de acceso 5078-5000 Usuario: Argentina Password: Argentina
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.