Created
March 5, 2015 20:49
-
-
Save grahamgilbert/6daba3da436750d17c8d to your computer and use it in GitHub Desktop.
boot_rom_version.py
This file contains 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/python | |
# Written in 10 minutes and tested on 10.10.2 only. Use with caution. | |
import subprocess | |
import plistlib | |
import os | |
from Foundation import CFPreferencesCopyAppValue | |
def boot_rom_version(): | |
cmd = ['/usr/sbin/system_profiler','-xml','SPHardwareDataType'] | |
task = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
(stdout, stderr) = task.communicate() | |
data = plistlib.readPlistFromString(stdout) | |
boot_rom_version = data[0]['_items'][0]['boot_rom_version'] | |
return boot_rom_version | |
def write_conditional(): | |
BUNDLE_ID = 'ManagedInstalls' | |
pref_name = 'ManagedInstallDir' | |
managedinstalldir = CFPreferencesCopyAppValue(pref_name, BUNDLE_ID) | |
conditionalitemspath = os.path.join(managedinstalldir, 'ConditionalItems.plist') | |
if os.path.exists(conditionalitemspath): | |
data_dict = plistlib.readPlist(conditionalitemspath) | |
else: | |
data_dict = {} | |
version = boot_rom_version() | |
data_dict['boot_rom_version'] = version | |
plistlib.writePlist(data_dict, conditionalitemspath) | |
if __name__ == '__main__': | |
write_conditional() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment