Skip to content

Instantly share code, notes, and snippets.

@xk
Forked from juanfal/plistread.rb
Last active December 10, 2015 09:19
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 xk/4413590 to your computer and use it in GitHub Desktop.
Save xk/4413590 to your computer and use it in GitHub Desktop.
//plistread.js, 2012-12-30 jorge@jorgechamorro.com
var plist= require('plist');
var shell= require('child_process').exec;
var puts= console.log;
//process.argv[0] -> "node"
//process.argv[1] -> "plistread.js"
//process.argv[2] -> inputFile
//process.argv[3..n] -> property list keys
if (process.argv.length < 3) {
puts ("Use: node plistread.js file.plist [attribute [, attribute ... ]]");
process.exit();
}
//Convertir la plist a texto xml:
var inputFile= process.argv[2];
var cmd= "plutil -convert xml1 -o - "+ inputFile;
shell(cmd, callback);
function callback (err, stdout, stderr) {
if (err) {
puts(err.message);
process.exit();
}
var plistAsText= stdout;
//Convertir la property list en un objeto:
var obj = plist.parseStringSync(plistAsText);
//Si se especifican + argumentos, presentar sólo los campos que se especifican:
if (process.argv.length > 3) {
for (var i=3 ; i<process.argv.length ; i++) {
var key= process.argv[i];
puts(key + " -> ", obj[key]);
}
}
else {
puts(plistAsText);
}
}
/*
$ node plist.js /Users/jorge/Library/Preferences/com.apple.finder.plist BrowserWindowState
BrowserWindowState -> [ { BrowserViewState: { ListViewScrollOrigin: '{0, 766}' },
ShowPathbar: false,
ShowSidebar: true,
ShowStatusBar: true,
ShowToolbar: true,
SidebarWidth: 191,
TargetPath:
[ 'file://localhost/Users/jorge/',
'file://localhost/Users/jorge/Library/',
'file://localhost/Users/jorge/Library/Preferences/' ],
TargetURL: 'file://localhost/Users/jorge/Library/Preferences/',
ViewStyle: 'List',
WindowBounds: '{{24, 234}, {944, 623}}' } ]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment