I'm writing code in AppleScript to glue an Obj-C Cocoa app to some other stuff. I'm very unfamiliar with AppleScript on also learning Cocoa, so of course I have all kinds of bugs in my code to work out, and I need at least some logging.
However, output from the AppleScript 'log' command doesn't seem to end up in XCode's d开发者_开发知识库ebugger console and calling NSLog doesn't seem to work. Is there any way I can send output to the Debugger Console from within an AppleScriptObjC class method?
(suggestion: new applescriptobjc tag on this Q -- I can't create new tags yet)
I don't use applescriptobjc, so I'm not sure. However, I used to use Applescript Studio so maybe my experience there applies. I noticed that you can't have a log (or NSLog) statement inside of an application tell block of code. Basically if you do that then you are telling the application to log something and the application doesn't know the log command... so it wouldn't work. As such you have to get your log statements out of application tell blocks or use use tell me to log "something" in the tell block... which essentially tells applescript to do the logging.
Not ideal because this logs to the console and uses the shell, but this should at least get you something that works:
log_entry("Hello, World!")
on log_entry(theLine)
do shell script "echo " & theLine & " >> ~/Library/Logs/AppleScript-events.log"
end log_entry
精彩评论