Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
Created April 6, 2012 01:22
Show Gist options
  • Save rockpapergoat/2315784 to your computer and use it in GitHub Desktop.
Save rockpapergoat/2315784 to your computer and use it in GitHub Desktop.
format output for use with casper extension attributes. to use, plug in the app name (Safari.app) as $4 in casper's web interface.
#!/usr/bin/env ruby -wKU
# 110224, revised with loop to accept an array
# 110425, swapped order of variable definition in get_version
# 120405, format output for use as casper extension attribute
def get_version(apps)
apps.each do |app|
if app.include?("/Applications/")
short = app.sub(/\/Applications\//, '')
elsif app.include?("/Applications/Utilities/")
short = app.sub(/\/Applications\/Utilities\//, '')
end
if File.exists?("#{app}/Contents/Info.plist")
version = `/usr/bin/defaults read "#{app}"/Contents/Info CFBundleShortVersionString 2> /dev/null`.chomp
$?.success? ? version : "ERROR: could not get version"
return version
else
version ="#{short} is not installed."
return version
end
end
end
apps = ARGV
if ARGV.size < 4
puts "<result>pass me an app name</result>"
else
puts "<result>#{get_version(ARGV[3])}</result>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment