使用JavaScript自动化(JXA)创建的plist [英] Use Javascript for automation (JXA) to create a plist

查看:314
本文介绍了使用JavaScript自动化(JXA)创建的plist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待到建立一个JXA建立一个plist中。我的出发点是一个AppleScript,我发现这里。我想出了这个片断:

I'm looking into creating a JXA to build a plist. My starting point is an AppleScript that I found here. I came up with this snippet:

var se = Application('System Events');

var item1 = se.PropertyListItem({kind: "string", name: "employee_name", value: employeeName}).make();

var plistFile = se.PropertyListFile({name: '/Users/armando/Desktop/x.plist', PropertyListItem: [item1]}).make();

ScriptEditor编译没有错误,该文件得到了创建但是没有条目上的文件制作。我想我缺少如何填充在实​​际项处理的PropertyListFile属性的东西。

ScriptEditor compiles without errors, the file got created but no entries are produced on the file. I guess I'm missing something on how to populate the PropertyListFile property where the actual entries are handled.

有关如何正确使用与JXA系统事件的plist中任何线索?

Any clue about how to correctly use JXA with System Event's plist?

(如果你想知道为什么不使用AppleScript的做法是因为我从Excel通过自动化拉低数据,但需要验证数据类型的一致性和空...的JavaScript在我看来,寻找到一个更直接的方法变量类型,并根据需要进行更正)

(in case you wonder why not use the AppleScript approach is because I'm pulling the data from Excel through automation but need to validate data type consistency and nulls... javascript seemed to me a more straight forward approach to look into variable types and make corrections as needed)

推荐答案

创建属性列表文件,系统活动是非常乏味的。结果
随着JXA你可以直接使用的Objective-C code。

Creating property list files with System Events is very tedious.
With JXA you can use Objective-C code directly.

var employeeName = "John Doe";

var item1 = { "employee_name" : employeeName };
var plist = $.NSDictionary.dictionaryWithDictionary(item1);
plist.writeToFileAtomically( '/Users/armando/Desktop/x.plist', true);

这篇关于使用JavaScript自动化(JXA)创建的plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆