Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to feed the Application directory into an array and then use PlistBuddy with the entries to retrieve version info about each application that are installed. Currently it seems to be not separating the list into individual array entries.

    apps=$(ls /Applications)
        for i in "$apps"
            do
                 /usr/libexec/plistbuddy -c Print:CFBundleShortVersionString: "$i"/Contents/info.plist
            done
share|improve this question

2 Answers 2

up vote 3 down vote accepted

That's because you are not creating an array. apps is a string that contains the result of ls /Applications. Anyway, you don't need the ls, try something like this:

for i in /Applications/*
 do
  /usr/libexec/plistbuddy -c Print:CFBundleShortVersionString: "$i"/Contents/Info.plist
done
share|improve this answer
1  
Isn't info.plist usually written with uppercase I? –  Daniel Beck Apr 1 '13 at 20:12
    
@DanielBeck thanks, fixed. I don't have a Mac so I just copied directly from the OP's question –  terdon Apr 2 '13 at 14:59

Some applications didn't have a CFBundleShortVersionString key. You could also use defaults or search for applications with mdfind:

IFS=$'\n'; for f in $(mdfind kMDItemContentType=com.apple.application-bundle); do printf %s "${f##*/}:"; defaults read "$f/Contents/Info.plist" CFBundleShortVersionString 2> /dev/null || defaults read "$f/Contents/Info.plist" CFBundleVersion 2> /dev/null || echo; done

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.