Last active
August 26, 2015 19:16
-
-
Save Koze/ac2437caba9e2ce32c73 to your computer and use it in GitHub Desktop.
Write plist file with JavaScript for Automation and Objective-C Bridge.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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