Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'contextual menu add-in' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
contextual menu add-in
Authored by: sinjin on Dec 22, '04 01:22:02AM
Love it. I've been wanting something like this for a long time. Should work nicely until I can justify buying Script Debugger.

Here are some tweaks that I think are helpful. This allows you to "control-click" or "right-click" in your Script Editor document to insert the line of code for logging a variable. It assumes you've copied the variable of interest to the clipboard first. Also keeps track of the variable name as well as value and adds a breaking line between runs to make reading the output a little easier.

Start off with a "templateScript.scpt", i.e. the common code to begin all your works in progress:


--Common code for logging:
set logScript to load script alias ¬
	((path to library folder from user domain as string) ¬
		& "Scripts:[AppleScript]:logger.scpt")
property logIt : true --toggle logging
if logIt then --adds breaking line to output between runs
	do shell script "echo " & "--" & " >> ~/Library/Logs/AppleScript-events.log"
end if
--
--Paste following after "theVar" you are observing:
--Logger("theVar", theVar , logIt) of logScript

The logging applescript itself, "logger.scpt" saved to whatever path you use in the code above:

on Logger(theVar, theVal, logIt)
	if logIt then
		set theLine to (do shell script ¬
			"date  +'%Y-%m-%d %H:%M:%S'" as string) ¬
			& " " & theVar & " " & theVal
		do shell script "echo " & theLine & ¬
			" >> ~/Library/Logs/AppleScript-events.log"
	end if
end Logger
Finally the contextual menu add-in, "loggerTag.scpt", that lets you take any variable you've saved to the clipboard and insert the logging call for it wherever you like. Save this script in "~/Library/Scripts/Script Editor Scripts/" then restart Script Editor.

set theVar to «class ktxt» of ((the clipboard as text) as record)
set theText to return & "Logger(\"" & theVar & ¬
	"\", " & theVar & " , logIt) of logScript" & return
tell application "Script Editor"
	tell front document
		set the contents of the selection to theText
	end tell
end tell
One more thing that would be nice is an applescript that will go through a document and delete the logger lines to clean up the code when you are all finished (ha! like that ever happens!). Some other day.

[ Reply to This | # ]