My log handler, logs Name, Time, and a Comment. Basicly the same.
my DoLog("File Error", "Not Closed")
on DoLog(TheName, TheComment)
set the LogFile to ((path to desktop) as text) & "Script.log"
try
open for access file the LogFile with write permission
set TimeStamp to do shell script "date -n '+%d/%m/%Y %H:%M:%S'"
write ((TheName as string) & tab & TimeStamp & tab & (TheComment as string) & return) to file the LogFile starting at eof as string
close access file the LogFile
return true
on error
try
close access file the LogFile
return false
end try
end try
end DoLog
You open and close files, becuase if it errors you create whats called a leak. Program Script Debugger has a feature to help close leaks. Best is open, write, close, if error, close.
I do a tab delimited method so you can easily open in a database or back into AppleScript.
There is a log command, with start log, stop log. Which goes the the log console in Applescript Studio, Or in Script Debugger.
Just add the Log On/Off feature to mine, good idea.
So it now go like this
property LogStatus : true
my DoLog("File Error", "Not Closed")
on DoLog(TheName, TheComment)
if LogStatus is true then
set the LogFile to ((path to desktop) as text) & "Script.log"
try
open for access file the LogFile with write permission
set TimeStamp to do shell script "date -n '+%d/%m/%Y %H:%M:%S'"
write ((TheName as string) & tab & TimeStamp & tab & (TheComment as string) & return) to file the LogFile starting at eof as string
close access file the LogFile
return true
on error
try
close access file the LogFile
return false
end try
end try
end if
end DoLog
With your question is there a kill feature. I dont know of a alsolutely anywhere kill. Expect pressing the Stop button or command period (I’ll try a GUI of that for fun, if you are running from non script editer, eg script menu, then you are out of luck). A return is a good method in root of your script. But if your are down a few levels in the stack, eg in a handler reutrn just exits the handler. You could return false, then ckeck for false and return again all the way out. Pain.
return
beep -- No beep as it exited
I hope someone else knows as a kill method would be useful
Have fun