0

Ok so here is the problem. I am trying to get an array of installed applications and versions.

So far what I have discovered is that I can run this command:

system_profiler SPApplicationsDataType > log.txt

Which will give me a txt file with the following format:

Applications:

MacTubes:

  Version: 3.1.5
  Obtained from: Unknown
  Last Modified: 9/15/12, 2:41 AM
  Kind: Universal
  64-Bit (Intel): No
  Location: /Volumes/Storage/MacTubes.app

Boom:

  Version: 1.6
  Obtained from: Identified Developer
  Last Modified: 10/12/12, 3:24 AM
  Kind: Intel
  64-Bit (Intel): No
  Signed by: Developer ID Application: Global Delight Technologies Pvt. Ltd, Developer ID Certification Authority, Apple Root CA
  Location: /Volumes/Storage/Boom.app
  Get Info String: 1.6  Copyright © 2008 - 2012, Global Delight Technologies Pvt. Ltd.

World of Goo:

  Version: 1.30
  Obtained from: Unknown
  Last Modified: 2/8/10, 8:43 AM
  Kind: Universal
  64-Bit (Intel): No
  Location: /Volumes/Storage/Misc/World of Goo.app
  Get Info String: 1.30, Copyright © 2008 2D Boy LLC

VZAccess Manager:

  Version: 4.3.0
  Obtained from: Unknown
  Last Modified: 12/17/09, 8:48 PM
  Kind: Universal
  64-Bit (Intel): No
  Location: /Volumes/Storage/Misc/VZAccess Manager.app
  Get Info String: VZAccess Manager 4.3.0 Copyright © 2000-2008 Smith Micro Software, Inc.

ColorSync:

  Obtained from: Unknown
  Last Modified: 10/9/00, 12:00 PM
  Kind: Classic
  Location: /Volumes/Storage/Misc/System Folder/Control Panels/ColorSync

AppleTalk:

  Obtained from: Unknown
  Last Modified: 10/1/96, 12:00 PM
  Kind: Classic
  Location: /Volumes/Storage/Misc/System Folder/Control Panels/AppleTalk

I want to be able to take the Application name and the Version number and store them somehow preferably in an array. I'm not sure how to where to start since all entries look the same to me? I need to ignore entries without versions numbers as well.

  • What programming language are you using? – bdesham Dec 11 '13 at 15:47
  • I'd like to use C++ if I can, but whatever language is easiest. I think I can make the problem simpler I found an old post where they were doing something similar, but its not quite giving me the results they are getting. http://hintsforums.macworld.com/archive/index.php/t-109990.html If I could get it into that format of Name: Version it would make it much simpler to parse. However what they did isn't working for me, I need to get all apps anyways not just certain apps. – Macuserman17 Dec 11 '13 at 16:02

1 Answers1

1

Here’s an Awk script that will give you the output format you mentioned:

/^ {4}.+:$/ {
    sub(/^ {4}/, "", $0)
    last_application = $0
}

/^ +Version:/ {
    sub(/^ +Version: /, "", $0)
    print last_application " " $0
}

If you save it as script.awk you can run

awk -f script.awk log.txt

to get output like

MacTubes: 3.1.5
Boom: 1.6
World of Goo: 1.30
VZAccess Manager: 4.3.0

This has been tested with the /usr/bin/awk of OS X 10.9.0.

bdesham
  • 15,430
  • 13
  • 79
  • 123
  • In the above example where does the output go? Running the saved script does not alter log.txt, create a new file, or display the output in the terminal. – Macuserman17 Dec 11 '13 at 17:09
  • I did figure out that the following command in terminal yields the correct format but does have a few errors apparently there are some exceptions it can't handle. system_profiler SPApplicationsDataType | grep -B8 -E '()[^/]*\.app' | awk '/:$/ {printf $0}; /Version: / {print "",$2,$3}' – Macuserman17 Dec 11 '13 at 17:12
  • @Macuserman17 The output should go directly to the terminal. (Note that the script doesn’t print anything for applications without a version number.) – bdesham Dec 11 '13 at 17:47
  • It just goes to the next line like this: Administrators-MacBook-Pro-2:Desktop Admin$ awk -f script.awk log.txt Administrators-MacBook-Pro-2:Desktop Admin$ – Macuserman17 Dec 11 '13 at 18:03
  • @Macuserman17 The output you posted in your question is not the same as the actual output of the command. I’ve edited my answer; my code should work now. – bdesham Dec 11 '13 at 19:55
  • That's awesome. Thank you I had it sort of figured out, but that cleaned up my output and got rid of some of the extra stuff I was getting. – Macuserman17 Dec 11 '13 at 20:11