-
-
Save xk/4413590 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//plistread.js, 2012-12-30 [email protected] | |
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