title: How to retrieve an application's version string?
body: <p>Using the Mac OSX SDK, I wrote this simple test application to extract the version string from running applications.</p>
  
  <pre><code>int main()
  {
      NSWorkspace * ws = [NSWorkspace sharedWorkspace];
      NSArray * apps = [ws runningApplications];
      NSUInteger max= [apps count];
      for (NSUInteger i = 0; i &lt; max; i++)
      {
          NSRunningApplication *app = [apps objectAtIndex: i];
          pid_t pid = [ app processIdentifier ];
          ProcessSerialNumber psn = { kNoProcess, kNoProcess };
  
          if ( GetProcessForPID(pid, &amp;psn) != noErr )
              continue;
  
          CFDictionaryRef dictionary 
              = ProcessInformationCopyDictionary(&amp;psn, kProcessDictionaryIncludeAllInformationMask);
  
          const NSString * version 
              = reinterpret_cast&lt;const NSString*&gt;(CFDictionaryGetValue( dictionary, CFSTR("CFBundleShortVersionString") ));
  
          printf( "version for pid %d: \"%s\"\n", pid, [ version UTF8String ] );
      }
  }
  </code></pre>
  
  <p>but this does not work, it prints lines like:</p>
  
  <blockquote>
    <p>version for pid 34: "(null)"</p>
  </blockquote>
  
  <p><strong>SECOND TRY</strong>
  I get a bit closer if I try retrieving <code>CFBundleVersion</code> by changing the two last lines to:</p>
  
  <pre><code> const NSNumber * version
       = reinterpret_cast&lt;const NSNumber *&gt;(CFDictionaryGetValue( dictionary, CFSTR("CFBundleVersion") ));
   printf( "version for pid %d: \"%s\"\n", pid, [ [ version stringValue ] UTF8String ] );
  </code></pre>
  
  <p>but now the version is an integer, like 257633863, and I would like something like 1.23.0</p>