Pass stdin to plistbuddy

1.5k Views Asked by At

I have a script to show the content of the Info.plist of .ipa files:

myTmpDir=`mktemp -d 2>/dev/null || mktemp -d -t 'myTmpDir'`
unzip -q "$1" -d "${myTmpDir}";
pathToFile=${myTmpDir}/Payload/*.app/Info.plist
/usr/libexec/PlistBuddy -c "Print" ${pathToFile}

With large files this can take some time until they are extracted to the temp folder just to read a small Info.plist (xml) file. I wondered if I can just extract Info.plist file and pass that to plistbuddy? I've tried:

/usr/libexec/PlistBuddy -c "Print" /dev/stdin <<< \
$(unzip -qp test.ipa Payload/*.app/Info.plist)

but this yields

Unexpected character b at line 1
Error Reading File: /dev/stdin

The extraction is working fine. When running unzip -qp test.ipa Payload/*.app/Info.plist I get the output of the Info.plist file to the terminal:

$ unzip -qp test.ipa Payload/*.app/Info.plist
bplist00?&


!"#$%&'()*+5:;*<=>?ABCDECFGHIJKXYjmwxyIN}~N_BuildMachineOSBuild_CFBundleDevelopm...

How can I pass the content of the Info.plist to plistbuddy?

2

There are 2 best solutions below

2
mles On BEST ANSWER

I ended up with plutil as chepner suggested:

unzip -qp test.ipa Payload/*.app/Info.plist | plutil  -convert xml1 -r -o - -- -
0
battlmonstr On

Usually commands support "-" as a synonym of stdin, but this PlistBuddy tool doesn't.

But you can still extract just one file from your ipa, save it as a temporary file, and then run PlistBuddy on that file:

tempPlist="$(mktemp)"
unzip -qp test.ipa "Payload/*.app/Info.plist" > "$tempPlist"
/usr/libexec/PlistBuddy -c Print "$tempPlist"
rm "$tempPlist"