Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active August 26, 2015 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Koze/ac2437caba9e2ce32c73 to your computer and use it in GitHub Desktop.
Save Koze/ac2437caba9e2ce32c73 to your computer and use it in GitHub Desktop.
Write plist file with JavaScript for Automation and Objective-C Bridge.
// use Foundation.framework
ObjC.import('Foundation');
// get applicaiton
app = Application.currentApplication();
// use StandardAdditions
app.includeStandardAdditions = true;
array = [1, 2, 3];
array.push(['a', 'b', 'c']);
dict = {'key1': array};
dict['key2'] = 'abc';
dict['key3'] = {'x': 1, 'y': 2, 'z': 3};
// convert into Objective-C (NSDictionary)
object = ObjC.wrap(dict);
// open save dialog
options = {
defaultName: 'Untitled.plist',
defaultLocation:app.pathTo('desktop')
};
filePath = app.chooseFileName(options);
// write to file (Objective-C)
object.writeToFileAtomically(filePath.toString(), true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment