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.
Created
July 19, 2012 14:49
-
-
Save calebd/3144456 to your computer and use it in GitHub Desktop.
A better build date script for Xcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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