Skip to content

Instantly share code, notes, and snippets.

@calebd
Created Jul 19, 2012
Embed
What would you like to do?
A better build date script for Xcode

A Better Build Date

Showing a build date in an app is pretty easy using __DATE__ and __TIME__ but the format is fixed. This script allows you to control the date and time format and pull the build date from the Info.plist using the CMDBundleBuildTime key.

#!/usr/bin/ruby
# plist gem
require "rubygems"
begin
require "plist"
rescue LoadError => e
puts "You need to install the 'Plist' gem: [sudo] gem install plist"
exit 1
end
# xcode check
raise "Must be run from Xcode" unless ENV["XCODE_VERSION_ACTUAL"]
# gather constants
PRODUCT_PLIST = File.join(ENV["BUILT_PRODUCTS_DIR"], ENV["INFOPLIST_PATH"])
BUILD_TIME_VALUE = Time.now.strftime("%b %e, %y at %I:%M %p")
BUILD_TIME_KEY = "CMDBundleBuildTime"
# update product plist
if File.file?(PRODUCT_PLIST)
`/usr/bin/plutil -convert xml1 \"#{PRODUCT_PLIST}\"`
info = Plist::parse_xml(PRODUCT_PLIST)
if info
info[BUILD_TIME_KEY] = BUILD_TIME_VALUE
info.save_plist(PRODUCT_PLIST)
puts "Set #{BUILD_TIME_KEY} to #{BUILD_TIME_VALUE}"
end
`/usr/bin/plutil -convert binary1 \"#{PRODUCT_PLIST}\"`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment