Skip to content

Instantly share code, notes, and snippets.

@ronanrodrigo
Last active May 12, 2017 12:30
Show Gist options
  • Save ronanrodrigo/7b75cc3f81201494f2230aaef5efb6df to your computer and use it in GitHub Desktop.
Save ronanrodrigo/7b75cc3f81201494f2230aaef5efb6df to your computer and use it in GitHub Desktop.
Get app version @ Info.plist
import os
import plistlib
def main():
file = os.path.expanduser('path/to/Info.plist')
if os.path.exists(file):
plist_file = plistlib.readPlist(file)
print("{0} ({1})".format(plist_file['CFBundleShortVersionString'], plist_file['CFBundleVersion'])) # Ex. 1.0 (0)
else:
print('File %s does not exist' % file)
if __name__ == '__main__':
main()
@ronanrodrigo
Copy link
Author

ronanrodrigo commented May 12, 2017

Another approach is to use PlistBuddy with shell script...

short_version="$(/usr/libexec/PlistBuddy ./path/to/Info.plist -c "Print :CFBundleShortVersionString")"
bundle_version="$(/usr/libexec/PlistBuddy ./path/to/Info.plist -c "Print :CFBundleVersion")"
version="${short_version} (${bundle_version})"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment