是否有方法通过OS X中的终端获取有关连接的监视器和显示器及其分辨率的信息?我有一些在多个监视器上运行的安装,有时如果没有连接监视器,GFLW窗口似乎无法打开-我想检查监视器是否正确连接,并可能将其转储到日志文件中,但我还没有找到一种编程方法来做到这一点,而不深入Obj-C/可可
qq24tv8q1#
您可以使用system_profiler SPDisplaysDataType或defaults read /Library/Preferences/com.apple.windowserver.plist:
system_profiler SPDisplaysDataType
defaults read /Library/Preferences/com.apple.windowserver.plist
$ system_profiler SPDisplaysDataType Graphics/Displays: NVIDIA GeForce GT 640M: Chipset Model: NVIDIA GeForce GT 640M Type: GPU Bus: PCIe PCIe Lane Width: x16 VRAM (Total): 512 MB Vendor: NVIDIA (0x10de) Device ID: 0x0fd8 Revision ID: 0x00a2 ROM Revision: 3707 Displays: iMac: Display Type: LCD Resolution: 1920 x 1080 Pixel Depth: 32-Bit Color (ARGB8888) Main Display: Yes Mirror: Off Online: Yes Built-In: Yes Connection Type: DisplayPort $ defaults read /Library/Preferences/com.apple.windowserver.plist { DisplayResolutionEnabled = 1; DisplaySets = ( ( { Active = 1; Depth = 4; DisplayID = 69731456; DisplayProductID = 40978; DisplaySerialNumber = 0; DisplayVendorID = 1552; Height = 1080; IODisplayLocation = "IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/P0P2@1/IOPCI2PCIBridge/GFX0@0/NVDA,Display-A@0/NVDA"; IOFlags = 7; LimitsHeight = 1080; LimitsOriginX = 0; LimitsOriginY = 0; LimitsWidth = 1920; MirrorID = 0; Mirrored = 0; Mode = { BitsPerPixel = 32; BitsPerSample = 8; DepthFormat = 4; Height = 1080; IODisplayModeID = "-2147479552"; IOFlags = 7; Mode = 1; PixelEncoding = "--------RRRRRRRRGGGGGGGGBBBBBBBB"; RefreshRate = 0; SamplesPerPixel = 3; UsableForDesktopGUI = 1; Width = 1920; kCGDisplayBytesPerRow = 7680; kCGDisplayHorizontalResolution = 103; kCGDisplayModeIsInterlaced = 0; kCGDisplayModeIsSafeForHardware = 1; kCGDisplayModeIsStretched = 0; kCGDisplayModeIsTelevisionOutput = 0; kCGDisplayModeIsUnavailable = 0; kCGDisplayModeSuitableForUI = 1; kCGDisplayPixelsHigh = 1080; kCGDisplayPixelsWide = 1920; kCGDisplayResolution = 1; kCGDisplayVerticalResolution = 103; }; OriginX = 0; OriginY = 0; PixelEncoding = "--------RRRRRRRRGGGGGGGGBBBBBBBB"; Resolution = 1; Unit = 0; UnmirroredHeight = 1080; UnmirroredLimitsHeight = 1080; UnmirroredLimitsOriginX = 0; UnmirroredLimitsOriginY = 0; UnmirroredLimitsWidth = 1920; UnmirroredMode = { BitsPerPixel = 32; BitsPerSample = 8; DepthFormat = 4; Height = 1080; IODisplayModeID = "-2147479552"; IOFlags = 7; Mode = 1; PixelEncoding = "--------RRRRRRRRGGGGGGGGBBBBBBBB"; RefreshRate = 0; SamplesPerPixel = 3; UsableForDesktopGUI = 1; Width = 1920; kCGDisplayBytesPerRow = 7680; kCGDisplayHorizontalResolution = 103; kCGDisplayModeIsInterlaced = 0; kCGDisplayModeIsSafeForHardware = 1; kCGDisplayModeIsStretched = 0; kCGDisplayModeIsTelevisionOutput = 0; kCGDisplayModeIsUnavailable = 0; kCGDisplayModeSuitableForUI = 1; kCGDisplayPixelsHigh = 1080; kCGDisplayPixelsWide = 1920; kCGDisplayResolution = 1; kCGDisplayVerticalResolution = 103; }; UnmirroredOriginX = 0; UnmirroredOriginY = 0; UnmirroredResolution = 1; UnmirroredWidth = 1920; Width = 1920; } ) ); ForceOldStyleMemoryManagement = 0; }
2wnc66cl2#
您也可以使用一个名为cscreen的命令行工具:
cscreen
# install homebrew if you don't have it already /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # install cscreen brew install --cask cscreen # list displays cscreen -l
输出:
DisplayID Index Depth Width Height Refresh 1 1 32 1440 900 60 2 2 32 1920 1080 60 use -h to display all usage options
System Preferences
Security & Privacy
Homebrew package search
w7t8yxp53#
使用python获取带有数据的字典。
import Foundation, objc import Quartz iokit = {} iokitBundle = objc.initFrameworkWrapper( "IOKit", frameworkIdentifier="com.apple.iokit", frameworkPath=objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"), globals=globals() ) IOKit = Foundation._functiondefines.NSBundle.bundleWithIdentifier_('com.apple.framework.IOKit') functions = [('IOServiceGetMatchingService', b'II@'), ('IOServiceMatching', b'@*'), ("IODisplayGetFloatParameter", b'iII@o^f'), ("IODisplayGetIntegerRangeParameter", b'I'), ('IORegistryEntryCreateCFProperties', b'IIo^@@I'), ('IOPSCopyPowerSourcesByType', b'@I'), ('IODisplaySetFloatParameter', b'iII@f'), ("IOHIDGetActivityState", b'IBi'), ('IODisplayCopyFloatParameters', b'II^^{__CFDictionary}i'), ('IODisplaySetIntegerParameter', b'II^{__CFString=}ii'), ('IODisplayCreateInfoDictionary', b'^{__CFDictionary=}II'), ('IODisplaySetParameters', b'II^{__CFDictionary=}i') ] objc._objc.loadBundleFunctions(iokitBundle, iokit, functions) objc._objc.loadBundleFunctions(IOKit, globals(), functions) for var in variables: key = "{}".format(var[0]) if key in globals(): iokit[key] = globals()[key] var = iokit['IODisplayCreateInfoDictionary'](Quartz.CGDisplayIOServicePort(Quartz.CGMainDisplayID()), 0) print(var, sep=r' ')
3条答案
按热度按时间qq24tv8q1#
您可以使用
system_profiler SPDisplaysDataType
或defaults read /Library/Preferences/com.apple.windowserver.plist
:2wnc66cl2#
您也可以使用一个名为
cscreen
的命令行工具:输出:
注意:
cscreen
时,操作系统将不允许,因为它没有签名。System Preferences
中访问Security & Privacy
并允许它。Homebrew package search
w7t8yxp53#
使用python获取带有数据的字典。