Send Mac OS X Notification Center message via JavaScript - 10.10 Yosemite

限于喜欢 提交于 2020-01-15 07:58:10

问题


How can a message be sent to the Mac OS X Notification Center using the JavaScript for Automation functionality that was introduced in 10.10 Yosemite?


回答1:


Messages can be sent to Notification Center via Automator and Script Editor JavaScripts by using the includeStandardAdditions method from the core library. For example:

app = Application.currentApplication()
app.includeStandardAdditions = true
app.displayNotification('Basic message')

The Script Editor application has documentation that shows they rest of the options. It can be accessed from the "Window -> Library" Menu and choosing the "StandardAdditions" Library and searching for the "displayNotification" command.

This example uses the full set of options:

app = Application.currentApplication()
app.includeStandardAdditions = true

app.displayNotification('Advanced message', { 
  withTitle: 'Message Title',
  subtitle: 'Subtitle', 
  soundName: 'Sosumi'
})


来源:https://stackoverflow.com/questions/27414831/send-mac-os-x-notification-center-message-via-javascript-10-10-yosemite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!