Detecting a portable Mac
Posted: Sat Feb 21, 2026 3:58 pm
I created this after playing with IOKit to build my own battery monitoring app. Considering that portable Macs far outsell desktop models (85% to 15%) and have additional hardware like TouchID and a battery, this might be useful.
Use cases:
1. Portable Macs have 13" to 16" displays but still have much less screen real estate than a desktop model, so you can use this code to make simple adjustments to program defaults like how you may display certain information in the menu bar or default to smaller windows and dialog boxes.
2. If you ever need to monitor the battery, you can smartly determine if your program is actually running on a portable Mac and handle cases where the program is not running on a portable machine gracefully.
3. Since 2020, all portable Mac's support TouchID authentication, so you can use this as a quick way to assume the Mac has TouchID suppport (though you still should check if TouchID can be initialized).
4. Power use is much more critical for portable Macs, so knowing if your program is running on a portable, you can expose certain functions to give users more control.
It's pretty simple: It reads from the Mac's system dictionary for the key that reveals the current model is using a battery.
Use cases:
1. Portable Macs have 13" to 16" displays but still have much less screen real estate than a desktop model, so you can use this code to make simple adjustments to program defaults like how you may display certain information in the menu bar or default to smaller windows and dialog boxes.
2. If you ever need to monitor the battery, you can smartly determine if your program is actually running on a portable Mac and handle cases where the program is not running on a portable machine gracefully.
3. Since 2020, all portable Mac's support TouchID authentication, so you can use this as a quick way to assume the Mac has TouchID suppport (though you still should check if TouchID can be initialized).
4. Power use is much more critical for portable Macs, so knowing if your program is running on a portable, you can expose certain functions to give users more control.
It's pretty simple: It reads from the Mac's system dictionary for the key that reveals the current model is using a battery.
Code: Select all
ImportC "-framework IOKit"
IOServiceMatching.i(name.p-ascii)
IOServiceGetMatchingService.i(masterPort.i, matchingDictionary.i)
IOObjectRelease.i(object.i)
EndImport
Procedure.b IsPortableMac()
Protected batteryService.i
Protected result.b = #False
batteryService = IOServiceGetMatchingService(0, IOServiceMatching("AppleSmartBattery"))
If batteryService
result = #True
IOObjectRelease(batteryService)
EndIf
ProcedureReturn result
EndProcedure
; --- Test ---
If IsPortableMac()
Debug "Portable Mac (Battery Detected)"
Else
Debug "Desktop Mac"
EndIf