使用其他两个答案中提出的基本思想,我编写了以下脚本来确定您使用的是“正确的”视频卡(正确的=“使用电池并使用9400”还是“使用交流适配器并使用9600”)
我不知道这些脚本有多脆弱……它们依赖于以特定顺序出现在system_profile plist中的特定数据……但是这个顺序在我的机器上似乎是一致的。将其放置在这里,供任何通过Google找到它的人使用。
Ruby :(需要安装“ Plist” gem)
# video_profiler.rb
require 'rubygems'
require 'plist'
# calculate video data
data = `system_profiler SPDisplaysDataType -xml`
structured_video_data = Plist.parse_xml(data)
display_status = structured_video_data[0]["_items"][0]["spdisplays_ndrvs"][0]["spdisplays_status"]
if (display_status.eql?('spdisplays_not_connected')) then
card = '9400'
else
card = '9600'
end
# calculate power source data
data = `system_profiler SPPowerDataType -xml`
structured_power_data = Plist.parse_xml(data)
on_ac_power = (structured_power_data[0]["_items"][3]["sppower_battery_charger_connected"] == 'TRUE')
# output results
if (on_ac_power and card.eql?'9400') or (not on_ac_power and card.eql?'9600'):
result = 'You\'re on the wrong video card.'
else
result = "You\'re on the correct video card."
end
puts(result)
蟒蛇:
# video_profiler.py
from subprocess import Popen, PIPE
from plistlib import readPlistFromString
from pprint import pprint
sp = Popen(["system_profiler", "SPDisplaysDataType", "-xml"], stdout=PIPE).communicate()[0]
pl = readPlistFromString(sp)
display_status = pl[0]["_items"][0]["spdisplays_ndrvs"][0]["spdisplays_status"]
if (display_status == 'spdisplays_not_connected'):
card = '9400'
else:
card = '9600'
# figure out battery status
sp = Popen(["system_profiler", "SPPowerDataType", "-xml"], stdout=PIPE).communicate()[0]
pl = readPlistFromString(sp)
on_ac_power = (pl[0]["_items"][3]["sppower_battery_charger_connected"] == 'TRUE')
if (on_ac_power and card == '9400') or (not on_ac_power and card == '9600'):
result = 'You\'re on the wrong video card.'
else:
result = "You\'re on the correct video card."
pprint(result)