最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

osx yosemite - How to log to message window in Script Editor using JavaScript for Automation - Stack Overflow

programmeradmin3浏览0评论

"JavaScript for Automation" is brand new in OSX Yosemite. I am not familiar with AppleScript as I don't really like how verbose it is. But Javascript looks great! However, I can't figure out how to send debug messages to the message window of ScriptEditor! I've looked everywhere... Is this possible? What is the code to do it?

I tried:

console.log("Hello World");

But that doesn't work. Any ideas? This should be so simple!

Note: This isn't an HTML/Javascript question. I am talking about the App called "Script Editor" in OSX using the Javascript language instead of AppleScript. I would tag this question with "Script-editor" but SO won't allow me to tag.

"JavaScript for Automation" is brand new in OSX Yosemite. I am not familiar with AppleScript as I don't really like how verbose it is. But Javascript looks great! However, I can't figure out how to send debug messages to the message window of ScriptEditor! I've looked everywhere... Is this possible? What is the code to do it?

I tried:

console.log("Hello World");

But that doesn't work. Any ideas? This should be so simple!

Note: This isn't an HTML/Javascript question. I am talking about the App called "Script Editor" in OSX using the Javascript language instead of AppleScript. I would tag this question with "Script-editor" but SO won't allow me to tag.

Share Improve this question edited Dec 22, 2014 at 19:53 Kivak Wolf asked Dec 22, 2014 at 19:48 Kivak WolfKivak Wolf 8708 silver badges30 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

OK Apparently it was easy enough.

this.console.log("Hello World");

I found this by simply typing this into a script and running it. It returns back GlobalObject for this with plenty of interesting properties and functions including the console property which contains a log() function.

console.log() works but the output isn't in the default Result pane. Go to View->Show Log and then click the Messages tab.

The output is shown in grey text surrounded by /* */.

As of 10.11 you can view console messages from Script Editor in the Safari Web Inspector (yep!), which is very useful for debugging.

Enable this option in the Safari menus: Develop>[your-mac-name]>Automatically Show Web Inspector for JSContexts

(Note: You'll need to activate the Safari Develop menu in Preferences if you haven't done so)

Then in your Script Editor script include a debugger line, which will open the Web Inspector in Safari and pause your script execution. Note the script file must be saved to disk.

You can then see your console messages from Script Editor in the Safari Web Inspector Console.

For example, try running the following in Scripter and step through the script:

debugger
Mail = Application('Mail')
console.log("Mail App's ID is: " + Mail.id())

Note that you don't need "this."

Look in the Console tab of the Web Inspector and you should see: "Mail App's ID is: .apple.mail"

You can read more about this on the Apple Developer Site

发布评论

评论列表(0)

  1. 暂无评论