In my Mac OS X application, I would like to log the user's graphics card driver and model. What is the appropriate API to use?
I've not been able to find an API to find this information, but you can get some information about the display hardware by running the following command:
/usr/sbin/system_profiler SPDisplaysDataType
Using dtruss that command appears to be doing something with executable code in /System/Library/SystemProfiler/SPDisplaysReporter.spreporter/Contents/MacOS/SPDisplaysReporter, but it's a bit hard to tell what exactly.
Do you want to get the the Graphics Card Driver and Model provided by IORegistryExploer, an application showing the hierarchies about the Devices and Drivers?
If so, you may use command ioreg -l in the terminal, and then filter the information you need.
Of course, how execute shell command in your application is another question, you may use the API provided by Cocoa, NSTask, or use the system() function.
Related
I would like to know if it is possible to get the battery level of a connected Bluetooth device (for example, a headset) on Mac OSX.
I'm looking for a command line or a library that would offer this possibility.
Thanks.
There is no easy way to get this information without special application.
There is an app especially designed for this only purpose - called AKKU.
It worked with Bose and Sony's headphones (checked)
https://github.com/jariz/Akku/
Remember to download version 0.1.0-beta.10.
The app works after restart.
Just follow this guide: http://osxdaily.com/2014/05/18/how-to-check-bluetooth-keyboard-battery-levels-from-the-command-line-on-mac-os-x/
Basically:
You just need to know the name of the device and then use ioreg, like this:
ioreg -c <devicename> |grep '"BatteryPercent" ='
Additionally, you could retrieve broader battery information with:
ioreg -c BeatsBluetoothHeadset |grep Battery
Next time, just google ... Since a similar question was already answered https://apple.stackexchange.com/questions/215256/check-the-battery-level-of-connected-bluetooth-headphones-from-the-command-line
I have been searching through how to do gamepad and joystick support on Mac for some days and all resources that I found seems to suggest a pre-installed driver along with using Apple's HID API, which works.
The drawback about this approach is that each joystick and gamepad will require another kernel extension to be loaded, so it can be recognized by HID manager, or at least a code less Info.plist saying it conforms to the earlier installed driver. For instance, when I have an 360 Xbox driver KEXT in house, the Xbox controller from Microsoft will work, but not the Logitech one (I tried F710).
As Apple suggests the application that uses a gamepad or joystick should be able to do themselves at user space without introducing any KEXT stuff. Is there a way to do it?
The thing I had in mind was something like using IORegistry or IOUSB API to get the device when they get plugged in (USB Prober shows it at least). Then somehow get the description of the device, then use that description to register the device as a HID one. Then the whole HID manager can be used.
Am I on the right track? Or is there any other way to do this?
Since IOKit API actually provided keywords like kHIDUsage_GD_Joystick, and there's an ForceFeedback.h library, I suppose Apple designed their HID API with joystick and force feedback in mind. That's the slim hope I had that this might work.
Some reference documentation and open source project:
Colin Munro's 360 driver
HID API Documents
DDHID Project
After revisiting this, I found out the solution to be operating directly on the file descriptors of the device. libusb is an excellent library which greatly simplify your life on this and they have Mac supported.
xboxdrv link is a great example on how to operate on file socket using libusb.
In pseudo code, it should look like this:
enumerate device
detect kernel driver and detach it if possible
open device
file off a initial transfer
wait on the callback function to handle msg and error properly
start run loop or select on fd to call libusb_event_handle
Check libusb for more info link.
Is there any way to query the address space of a process on Mac?
On Windows, we use VirtualQuery, and on Linux, we parse /proc/self/maps (ugh).
Is there a system call or similar functionality on Mac?
The vmmap command-line utility will give you this information. I'm not sure that the APIs behind it are public, though.
mach_vm_region_info can be used for this. See http://www.newosxbook.com/src.jl?tree=listings&file=12-1-vmmap.c
How can I retrieve the information shown in the Mac's System Profiler app programatically? I'm actually interested in the USB section if that matters.
The OSX command line tool "ioreg" might give you want you want.
man ioreg
ioreg displays the I/O Kit registry. It shows the heirarchical registry as an inverted tree.
Also if you can/want to use Cocoa look at IOKit. IOKit is the OSX framework that talks to USB hardware.
Take a look at the system_profiler(8) command.
How does one go about creating a virtual CD driver on Mac OS X programatically?
I can't find any relevant Cocoa APIs or any pure C BSD solutions.
Any help or information is appreciated.
You would need to use the I/O Kit framework to develop your own device driver that would emulate a virtual CD drive. Here are some links to the relevant APIs to get you started.
I/O Kit Fundamentals
I/O Kit Device Driver Guidelines
Kernel Extension Programming Topics
There are several different answers people have proposed here. The issue at hand is what are you trying to accomplish. If you really want to emulate a CD ROM (down to the commandset) you will need to write a device driver. If your goal is merely to emulate a block device with contents similiar to a CD you can create a disk image using disk utility and let the builtin disk image driver handle it for you.
MacFUSE is useful if you want to present some sort of custom filesystem functionality, but if what you are looking for is something that has the same semantics as an optical disc (whether that is and block or command set level) it is the wrong tool.
If you're simply looking to mount an ISO or something then it's done through the Disk Utility, simply drag it into the side-bar and then select it and choose mount.
If you want to do it from code you can issue the hdiutil command, as shown here. I'm not sure if there's an API call to do it, but getting that command to do the work is quite painless.
The simplest way to mount a custom volume is MacFUSE. It handles the IOKit details for you and lets you write the implementation in user space. However, I don’t think you can make a MacFUSE “look like” a CD; you’d have to modify FUSE to achieve that.
I had a nosey around DAEMON Tools for Mac's driver:
/Library/Extensions/DAEMONToolsVirtualSCSIBus.kext/Contents/MacOS/DAEMONToolsVirtualSCSIBus
I disassembled the binary using Hopper and discovered they are using
IOSCSIProtocolServices.