Using Java 6 in OSX, how can I determine if the current hardware is a Desktop or a Laptop? I was looking through System.getProperty()
, but didn't find anything definitive.

- 4,744
- 8
- 33
- 64
-
Why do you want to know - many people use the laptop as a desktop e.g. external monitor and keyboard – mmmmmm Jul 03 '12 at 17:40
-
Why would you need to make this distinction? Desktop vs. Laptop is several levels of abstraction higher than you should likely be concerned with, especially in Java. – Dave Jul 03 '12 at 18:01
-
Who cares why they want to know this? It is important to them for some reason. There are hardware differences between MacPro and MacBook models that might be important. It might be some kind of IT cataloging application, who knows? Why does it really matter why? – Jul 03 '12 at 18:04
-
@Jarrod: Because we're curious? Using Java, it's rare to care what kind of hardware you're running on. What is the use-case? Maybe I'll encounter it in the future. – Dave Jul 03 '12 at 18:08
-
1Although I don't know why this generated so much interest, it's UI related. Completely cosmetic. – Cody S Jul 04 '12 at 00:04
3 Answers
You can query ioreg
for the model
via ProcessBuilder
, as shown here.
Addendum: Similar information may be obtained from the output of system_profiler
.
This info is not readily available to Java. You'll probably have to call to a native library to obtain that information. Here's a question that deals with that problem: Getting the Machine Type and other Hardware details through Cocoa API
You can use standard Unix tools to discover some of the information you may need to make this determination.
Here is an example from my machine:
>[jhr@Blackintosh] system_profiler SPHardwareDataType
Hardware Overview:
Model Name: Mac Pro
Model Identifier: MacPro3,1
Processor Name: Quad-Core Intel Xeon
Processor Speed: 2.33 GHz
Number of Processors: 1
Total Number of Cores: 4
L2 Cache: 4 MB
Memory: 8 GB
Bus Speed: 1.33 GHz
Boot ROM Version: MP31.006C.B05
SMC Version (system): 1.30f3
Serial Number (system): G8819IY0XYK
Hardware UUID: 8F6CD4F7-BA8F-5564-84DA-55A5AC59D42E
The Model Identifier:
tells you exactly what model of hardware is being used.
It would be a simple exercise to exec()
the command system_profiler SPHardwareDataType
and parse the response line by line and get what you need.
system_profiler
without any arguments gives you ever detail about the machine and the OS.
-
-
not really it is about 3.5 years old and it doesn't really have a Xeon, it has a Q8200, and it is based on a Gigabyte EP45-UD3P and a Sapphire Vapor-X 4970. I have another with a Q9950 that is faster that I use for a music production machine. – Jul 03 '12 at 19:07