技术控

    今日:75| 主题:49471
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] A Beginners Guide to JXA, JavaScript Application Scripting

[复制链接]
依旧爱你 发表于 2016-10-10 19:25:15
185 4

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
If you have ever done any scripting on the Mac, then you most likely have seen AppleScript . AppleScript has been the de facto standard for meshing applications together and for user interface scripting.  
   Since OS X 10.10 Yosemite , there is a second scripting language for user interface scripting: JavaScript for Automation (JXA) .  
   In this tutorial, I'll help you to learn this alternative to AppleScript with some real world examples.
  Running JXA

   There are many ways to run a JXA script. The standard way to run JXA script is with the Script Editor that is a part of the operating system.
     
A Beginners Guide to JXA, JavaScript Application Scripting-1 (interface,examples,standard,together,Running)
      Script Editor Set for JavaScript (JXA)       With the list box at the top left corner, under the stop button, set to JavaScript instead of AppleScript , you have a full JavaScript interpreter. To access the current application for scripting, add these lines:
  [code]//
// Get the current application and set it up
// for scripting.
//
var app = Application.currentApplication();
app.includeStandardAdditions = true;[/code]  The first line will get the JXA object for the application running the code. The second line allows you to add dialog boxes and other goodies to that application object.
  Now add this to the script:
  [code]//
// Send a message to the user.
//
app.displayAlert("This is a message");[/code]

A Beginners Guide to JXA, JavaScript Application Scripting-2 (interface,examples,standard,together,Running)
      Message Example      When you run this, it will display a message dialog with the text “This is a message”.
  If you want to pick from a list of items, add the following:
  [code]//
// Let the user pick from a list.
//
var lang = app.chooseFromList(['JavaScript', 'AppleScript', 'JXA'], { withPrompt: 'What is your favorite language?' });
app.displayNotification(lang, { withTitle: 'Language Chooser', subtitle: 'Your Choice is...' });[/code]   The chooseFromList() function takes an array of strings and an optional object with configuration options. The withPrompt configuration option allows you to set the text displayed above the list of strings. The string selected will be return.
   The displayNotification() function is then used to display a notification with the information supplied to the user. You can set the title and subtitle of the notification with the configuration object.
1234下一页
友荐云推荐




上一篇:Microservices in Flask
下一篇:Real-time applications using ASP.NET Core, SignalR & Angular
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

Music_life 发表于 2016-10-10 22:30:22
是爷们的娘们的都帮顶!大力支持
回复 支持 反对

使用道具 举报

月上舞袖 发表于 2016-11-7 13:39:38
来,来,干了这杯翔!
回复 支持 反对

使用道具 举报

爱看美女 发表于 2016-11-18 10:58:51
只想优雅转身,不料华丽撞墙。
回复 支持 反对

使用道具 举报

左眼角的淚痣 发表于 2016-11-18 22:50:52
众里寻他千百度,蓦然回首在这里!
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表