Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
Created February 24, 2011 14:52
Show Gist options
  • Save rockpapergoat/842247 to your computer and use it in GitHub Desktop.
Save rockpapergoat/842247 to your computer and use it in GitHub Desktop.
accepts an array as arguments on the command line or will loop through /Applications
#!/usr/bin/env ruby -wKU
# 110224, revised with loop to accept an array
def get_version(apps)
apps.each do |app|
if File.exists?("#{app}/Contents/Info.plist")
vers = `/usr/bin/defaults read "#{app}"/Contents/Info CFBundleShortVersionString`.chomp
puts "#{app.sub(/\/Applications\//, '')}: #{vers}"
$?.success? ? vers : "ERROR: could not get version"
else
puts "#{app} is not installed."
end
end
end
apps = ARGV
if ARGV.size == 0
puts "no argument(s) passed, so let's loop through all apps under /Applications.\n\n"
apps = Dir.glob("/Applications/*.app")
get_version(apps)
else
get_version(apps)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment