I’ve got about 2 dozen variables in my program and I would like to have the ability to print them out on a piece of paper so I can have a hard copy of the data. I’ve been having trouble coming up with a way to do this. I would appreciate any suggestions.
two problems:
¢ How can I get the name of the variable as a text string?
¢ Variables can be anything (dates, strings, numbers, lists, records), so you have to format the data to be able to print it.
Here is a subroutine from Hanaan Rosenthal’s book: AppleScript, a comprehensive guide
to display the value of the variable in a “printable” format
property debug : true
set a to {1, 2, 3, 4}
msg(a)
on msg(theValue)
local theClass, theValue, theClassString
if debug then
set theClass to class of theValue
set theClassString to theClass as string
if theClass is in {integer, real, number} then
display dialog theClassString & return & theValue
else if the class is string then
display dialog theClassString & return & "\"" & theValue & "\""
else if the class is date then
set theStringValue to theValue as string
display dialog theClassString & return & "date \"" & theValue & "\""
else if theClass is list then
set text item delimiters to ", "
set theStringValue to theValue as string
set text item delimiters to {""}
display dialog "List of " & (count theValue) & " items" & return & "{" & theStringValue & "}"
else
try
set theStringValue to theValue as string
display dialog theClassString & return & theStringValue
on error errorText
display dialog "Debug error:" & return & theClassString & return & errorText
end try
end if
end if
end msg
I would prefer to use the log function of AppleScript
After a little more research into this matter I have decided to export the data to TextEdit instead of just trying to get the program to print by itself. That should make things a little easier.