Post

Replies

Boosts

Views

Activity

macOS API for hardware model name?
If I go to "System Settings" -> "General" -> "About", it says "MacBook Air" and below that "M2, 2022" How can I get these strings programatically? The following C code gets me #include <stdio.h> #include <sys/sysctl.h> int main() { static const unsigned namelen = 2; int name[namelen] = {CTL_HW, HW_PRODUCT}; char buffer[256]; size_t bufferSize = sizeof(buffer); if (0 != sysctl(name, namelen, buffer, &bufferSize, NULL, 0)) { perror("sysctl"); return 1; } printf("%s\n", buffer); } the string "Mac14,2", which is the hardware model identifier. But I want to get the user-friendly model name, e.g. "MacBook Air (13-inch, M2, 2022)". How can I do this?
12
1
394
Nov ’24
Intermittent App Package Installation failure.
I work on a macOS application that functions as a daemon. To test it, I: Compile executables. Use pkgbuild and productbuild to build an application bundle. Use codesign and notarytool to sign and notarize the app. Install the app with /usr/sbin/installer -target LocalSystem -pkg .... This often overwrites the previous version of the app. Sometimes, the installation fails at the postinstall stage, when it can not find the application's install directory. We explicitly check for this error in our script: if ! [ -d "$APP_INSTALL_DIR"/Contents ]; then echo "directory ${APP_INSTALL_DIR}/Contents is missing" exit 1 fi This is unexpected! Even worse, some of our customers have occasionally seen the same issue! We use a postinstall script in order to install files into the /Library/LaunchDaemons and /Library/ LaunchAgents directories, and start the agent with launchctl bootstrap. Our preinstall script makes sure that the previous version of our application is fully uninstalled (so there is no confusion), and we wonder if that is part of the problem. While researching this error, I ran across a discussion of a similar issue on Stackoverflow: <https:// stackoverflow.com/questions/19283889>. One of the commenters there wrote: It appears that the OS X installer uses information about already installed packages and application bundles in order to decide where and if to install new packages. As a result, sometimes my installer did not install any files whatsoever, and sometimes it just overwrote the .app bundle in my build tree. Not necessarily the one used to build the installer, but any .app bundle that OS X had found. In order to get the installer to install the files properly I had to do two things: Tell OS X to forget about the installed package. sudo pkgutil --forget <package id> Not sure if this is needed for you nor in my case, but it is probably a good idea anyway. Delete all existing .app bundles for the app. If I didn't do this, the existing app bundle was overwritten on install instead of the app being placed in /Applications. Maybe there is a way to prevent this while building the installer package, but I haven't found it. On the other hand, the man page for pkgutil says not to use --forget from an installer: Discard all receipt data about package-id, but do not touch the installed files. DO NOT use this command from an installer package script to fix broken package design. What is the correct approach to fix this problem?
5
0
387
Jul ’24
Getting the Wi-Fi router BSSID from a Daemon.
Our macOS application (running as a LaunchDaemon) has been able to report the current Wi-Fi SSID and BSSID (if connected) using the airport command. Since airport has been removed from macOS, we have not been able to collect BSSID information. First, I demonstrate that the BSSID exists: I can option-click the Wi-Fi status menu icon and see the following: Wi-Fi Interface Name: en0 Address: a8:8f:d9:52:10:7d * * * Enable Wi-Fi Logging Create Diagnostics Report... Open Wireless Diagnostics... * * * Known Network polymorphic IP Address: 192.168.86.50 Router: 192.168.86.1 Security: WPA2 Personal BSSID: 88:3d:24:ba:36:81 Channel: 149 (5 GHz, 80 MHZ) Country Code: US RSSI: -60 dBm Noise: -89 dBm Tx Rate: 520 Mbps PHY Mode: 802.11ac MCS Index: 5 NSS: 2 * * * Other Networks * * * Wi-Fi Settings... This says to me that: The WiFi router I am connected to has SSID = polymorphic. The WiFi router I am connected to has BSSID = 88:3d:24:ba:36:81. My computer's Wi-Fi hardware has MAC address = a8:8f:d9:52:10:7d. My computer's Wi-Fi interface name = en0. To get this information now (from within an application), I have attempted to run: /usr/sbin/networksetup -listallhardwareports The output of that command includes the following Hardware Port: Wi-Fi Device: en0 Ethernet Address: a8:8f:d9:52:10:7d To get the SSID, I can then execute: $ /usr/sbin/networksetup -getairportnetwork en0 Current Wi-Fi Network: polymorphic But I still can't get the router's BSSID. So I try $/usr/sbin/networksetup -getinfo 'Wi-Fi' DHCP Configuration IP address: 192.168.86.50 Subnet mask: 255.255.255.0 Router: 192.168.86.1 Client ID: IPv6: Automatic IPv6 IP address: none IPv6 Router: none Wi-Fi ID: a8:8f:d9:52:10:7d Still no new information. $ /usr/sbin/networksetup -getmacaddress en0 Ethernet Address: a8:8f:d9:52:10:7d (Device: en0) This is not helpful either. Let's try another approach: $ /usr/sbin/netstat -nr -f inet | grep ^default default 192.168.86.1 UGScg en0 This tells me that my router's IP address is 192.168.86.1. The arp tool should be able to translate $ /usr/sbin/arp -a -n | grep "(192.168.86.1)" ? (192.168.86.1) at 88:3d:24:ba:36:7f on en0 ifscope [ethernet] This tells me that the router's MAC address is "88:3d:24:ba:36:7f", but it is not the same value as the router's BSSID, which we know to be 88:3d:24:ba:36:81! Another approach. I wrote the following Swift program: import CoreWLAN let c : CWWiFiClient = CWWiFiClient.shared() if let ifs : [CWInterface] = c.interfaces() { for i in ifs { print( i.interfaceName ?? "<nil>", i.powerOn(), i.ssid() ?? "<nil>", i.bssid() ?? "<nil>") } } When executing it with swift, I got: en0 true polymorphic <nil> So for some reason, the CoreWLAN API is hiding the BSSID, but not the SSID. When I use swiftc to compile before executing, I get: en0 true <nil> <nil> Why is the CoreWLAN API now hiding the SSID as well? I even tried an Objective-C program: // Link with: // -framework Foundation // -framework CoreWLAN #include <stdio.h> #include <CoreWLAN/CoreWLAN.h> void printWifi() { NSArray<CWInterface*>* ifs = [[CWWiFiClient sharedWiFiClient] interfaces]; for (CWInterface* i in ifs) { printf("%s %s %s %s\n", [i.interfaceName UTF8String], [i powerOn] ? "true" : "false", [[i ssid] UTF8String], [[i bssid] UTF8String]); } } int main() { printWifi(); return 0; } It prints out: en0 true (null) (null) Based on https://developer.apple.com/forums/thread/131636, I tried // Link with: // -framework Foundation // -framework CoreWLAN // -framework CoreLocation #include <stdio.h> #include <CoreWLAN/CoreWLAN.h> #include <CoreLocation/CoreLocation.h> void printWifi() { NSArray<CWInterface*>* ifs = [[CWWiFiClient sharedWiFiClient] interfaces]; for (CWInterface* i in ifs) { printf("%s %s %s %s\n", [i.interfaceName UTF8String], [i powerOn] ? "true" : "false", [[i ssid] UTF8String], [[i bssid] UTF8String]); } } CLLocationManager* startCoreLocation() { CLLocationManager* mgr = [[CLLocationManager alloc] init]; [mgr requestAlwaysAuthorization]; [mgr startUpdatingLocation]; return mgr; } int main() { CLLocationManager* locMgr = startCoreLocation(); printWifi(); return 0; } That change did not seem to make a difference. After more work, I found that I can not even figure out CLLocationManager authorization. So I attempted to create a minimal program that can get that: https://github.com/HalCanary/location. I am not sure how to proceed here. What is wrong with my location code? Will our application need to get the com.apple.security.personal-information.location entitlement in order to get the BSSID?
4
0
852
Jul ’24
How to print all installed configuration profiles on MacOS.
In https://support.apple.com/guide/mac-help/configuration-profiles-standardize-settings-mh35561/mac, Apple says View an installed configuration profile: On your Mac, choose Apple menu → System Settings, click Privacy and Security in the sidebar, then click Profiles on the right. (You may need to scroll down.) Select a profile in the Profiles list to view information about it. Is there a way to get this information on the command line or via an API? I would like to include a dump of all of this info in my debug logs of my application, so that I know when it misbehaves whether or not the system permissions were set correctly.
1
0
2.4k
Apr ’23
IOPSCopyPowerSourcesInfo → kIOPSBatteryHealthKey returning incorrect value
IOPSCopyPowerSourcesInfo → kIOPSBatteryHealthKey returning incorrect value Background: I write software to monitor computer system health. I'm having problems getting battery health information on my new M2 notebook. Given the following Objective-C program: #include <Foundation/NSObjCRuntime.h> #include <IOKit/ps/IOPSKeys.h> #include <IOKit/ps/IOPowerSources.h> #include <assert.h> int main() { CFTypeRef psInfo = IOPSCopyPowerSourcesInfo(); assert(psInfo != NULL); CFArrayRef list = IOPSCopyPowerSourcesList(psInfo); assert(list != NULL); long count = CFArrayGetCount(list); for(long i = 0; i < count; i++) { CFDictionaryRef ps = IOPSGetPowerSourceDescription( psInfo, CFArrayGetValueAtIndex(list, i)); assert(ps != NULL); CFStringRef deviceName = (CFStringRef)CFDictionaryGetValue( ps, CFSTR(kIOPSNameKey)); assert(deviceName != NULL); CFStringRef serialNumber = (CFStringRef)CFDictionaryGetValue( ps, CFSTR(kIOPSHardwareSerialNumberKey)); assert(serialNumber != NULL); CFStringRef health = (CFStringRef)CFDictionaryGetValue( ps, CFSTR(kIOPSBatteryHealthKey)); assert(health != NULL); NSLog(@"\nName=\"%@\"\nSerialNumber=\"%@\"\n" "BatteryHealth=\"%@\"\n", (__bridge NSString*)deviceName, (__bridge NSString*)serialNumber, (__bridge NSString*)health); } CFRelease(list); CFRelease(psInfo); return 0; } and looking at the IOPSKeys.h header, I expect to get one of "Poor", "Fair", or "Good" for the value of kIOPSBatteryHealthKey. https://opensource.apple.com/source/IOKitUser/IOKitUser-1845.81.1/ps.subproj/IOPSKeys.h.auto.html Instead, on my 2022 M2 Macbook Air running 13.2.1 (22D68), I get the following output: Name="InternalBattery-0" SerialNumber="F8Y2422145S10X2A7" BatteryHealth="Check Battery" At the same time, the "System Information app says "Condition: Normal". Am I missing something? This seems to be a bug, right? Should I look into filing a Technical Support Incident?
2
0
1.2k
Mar ’23