Re: debugging folder action scripts
Re: debugging folder action scripts
- Subject: Re: debugging folder action scripts
- From: "Adam K. Wuellner" <email@hidden>
- Date: Tue, 27 Apr 2004 22:44:30 -0500
On Apr 27, 2004, at 10:06 PM, Sander Tekelenburg wrote:
At 20:20 -0500 UTC, on 2004/04/27, Adam K. Wuellner wrote:
[...]
I am a little dismayed to see very little in the way of debugging
features in Script Editor.
Take a look at some of the third-party editors, like "Smile" or "Script
Debugger".
Also, you can encapsulate your code in a try block, have that catch
errors
and write them to a log. You'd have to write all that code yourself
though
(but it's a good exercise ;) and you'll end up with a handler that
you'll use
more often) and you'd only catch errors, not all events. Something
along
these lines:
try
-- do stuff
on error m number n
my errHandler(1, n, m)
end try
try
-- do more stuff
on error m number n
my errHandler(2, n, m)
end try
try
-- do more stuff
on error m number n
my errHandler(3, n, m)
end try
on errHandler(errNum, n, m)
set the_log to open for access [path to file] with write permission
try
write errNum & tab & n & tab & m & return to the_log starting at eof
close access the_log
end try
close access the_log
end errHandler
How effective this is will mostly depend on the amount of code of your
script. If you need to encapsulate 20 statements in try blocks, it
sucks... ;)
Note that I use this approach mostly for idle handlers; scripts that
run
continusouly, under changing circumstances. (I have it also insert the
date&time of the error in that case.) I haven't used it for
FolderActions,
but it seems to me it would be useful there too. Same with droplets.
You'd have to remember to look in the log now and then of course. If
you tend
to forget, you could have the script open it automatically, or beep at
you or
something like that.
I, unluckily, picked a folder action as my
first AppleScript project, for which the code sits in an 'on adding
folder items' block. When I ran the code, it was very difficult to
tell where it was failing. No errors, despite not getting the desired
results. I wrapped most of it in an 'on run' block in a new script,
Can be useful if you know what you're doing. With this approach, I'd
advice
to only grab portions of your script though. Make sure each little
part is
correct. If after that you're still getting errors, you know that the
problem
is likely to be specifically related to the special circumstances of
the
script (in this case its FolderAction-ness). By then you _know_ you
need
better debugging tools.
and was treated to a bunch of informative error messages when I ran it
from Script Editor (instead of having the folder action trigger the
'real' script).
The problem with that approach is, or at least can be if you're not
fully
aware of it, that you then run the script under different
circumstances, so
the part of your code where that matters will generate different
errors/successes.
Thanks very much for the advice.
I'll have a look at the editors you mentioned, and I'm going to take a
whack at writing an error handler tomorrow.
--
Adam Wuellner
email@hidden
_______________________________________________
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.