How to debug a droplet

Everytime I try to debug a script, Events panel (in AppleScript Editor) is a powerfull tool.
But When I have to debug a droplet… i can use this (droplet start from Finder, not from AS).

How do you do that? Put some “display dialog”? Or something else?

A droplet is just a script with an “on open something” handler. I always debug them by commenting out the “on open …” and “end open” and specifiying “something” some other way (like by choosing it). When I’ve got the script working that way, I replace the handler lines.

You are right.
But I hoped to find a free/shareware software to see AppleScript log file better that Events panel.

You can build error trapping/logging into your scripts :smiley:

That’s generally what I do. I have a generic logMe handler that’s been evolving over the years, it’s in all my scripts of any noteworthy length. The latest tweak to it now has it driven by a global variable so that I can turn off all the logging when the program is “finished” or on again if I need to further debug.

Here’s one of the latest versions:

on logMe(log_string, indent_level)
	if g_debug is "true" then --allows turning the debugger on and off so logMe's can be left in final version
		set log_file_name to "Program Name Log.txt"
		set home_folder_path to path to home folder
		set log_file_path to (home_folder_path & "Library:Logs:" & log_file_name) as text
			writeEntry(log_string, indent_level, log_file_path)
		on error
			tell application "Finder"
				make new file at log_file_path with properties {name:log_file_name}
				close access (log_file_path as alias)
			end tell
			writeEntry(log_string, indent_level, log_file_path)
		end try
	end if
end logMe

on writeEntry(log_string, indent_level, log_file_path)
	tell application "Finder"
		open for access file log_file_path with write permission
		repeat indent_level times
			write tab to (log_file_path as alias) starting at eof
		end repeat
		write (log_string & return) to (log_file_path as alias) starting at eof
		close access (log_file_path as alias)
	end tell
end writeEntry

A typical call to this is simply:

	logMe("Something happened", 3)

I use it for troubleshooting as well as general logging of steps taken. The indent_level just accommdates making the log entries more human readable during heavy troubleshooting.