views:

45

answers:

2

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 debugger 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)

+1  A: 

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.

regulus6633
I'm not sure that's entirely correct. I've put log statements in all sorts of places and never had a problem. If it is a problem, then the log command can just as easily be abstracted to a subroutine (e.g., like my answer to the OP's question) which does away with the current tell statement.
Philip Regan
Went and tested it, this works for me where normal log statments don't.
Walter Mundt
A: 

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
Philip Regan