PDA

View Full Version : How do I find my Macs model from terminal?




glossywhite
Sep 5, 2009, 06:45 PM
Hi. what command do I issue to Terminal.app, to get my Mac model; for example "Macmini3,1". It HAS to be Terminal, thanks.

[EDIT]

FOUND IT!!:

sysctl hw.model



Guiyon
Sep 5, 2009, 06:48 PM
try:

/usr/sbin/system_profiler SPHardwareDataType

The information you want will be next to the "Model Identifier" key

angelwatt
Sep 5, 2009, 06:49 PM
Try this out,
system_profiler | grep "Model Id"

Peace
Sep 5, 2009, 06:50 PM
Why use the terminal when it's right there in the system profile ? :confused:

glossywhite
Sep 5, 2009, 06:57 PM
... because I am trying to find out if this PERL script is checking model ID of Macs, when installing Snow Leopard. Can someone shed some light on what this script does?:

#!/usr/bin/perl

########################################################
my $TARG = $ARGV[0];
my $SYSTEM_VERS = $TARG . "/System/Library/CoreServices/SystemVersion.plist";
my $EXIT_VALUE = 0;
########################################################

DO_CHECKS: {
unless (-e $SYSTEM_VERS) {
$EXIT_VALUE = 1;
last;
}

if (CheckVersion("$SYSTEM_VERS", "8G1165", "ProductBuildVersion", "<")) {
$EXIT_VALUE = 1;
last;
}

unless(SystemPaths($TARG)) {
$EXIT_VALUE = 1;
last;
}
}

exit($EXIT_VALUE);

########################################################

sub SystemPaths {
my $targ = shift();

while(<DATA>) {
chomp();
if($_ eq "") {
next;
}
-e($targ . $_) || return(0);
}
return(1);
}

sub CheckVersion {
my $path = $_[0];
my $version = $_[1];
my $keyName = $_[2];
my $operator = $_[3];

if (! -e $path) {
return 0;
}

if (!$operator) {
$operator = "==";
}

my $oldSeperator = $/;
$/ = \0;

open( PLIST, "$path") || do {
return 0;
};

$plistData = <PLIST>;
$plistData =~ /<dict>(.*?)<\/dict>/gis;

@items = split(/<key>/, $plistData);

shift @items;
foreach $item (@items) {
$item =~ /(.*?)<\/key>.*?<string>(.*?)<\/string>/gis;
$versiondata{ $1 } = $2;
}

close(PLIST);

$/ = $oldSeperator;

# ProductBuildVersion style keys
$versiondata{$keyName} =~ /(\d+)([A-Z])(\d+)/ && ($versiondata{$keyName} = "$1.".ord($2).".$3");
$version =~ /(\d+)([A-Z])(\d+)/ && ($version = "$1.".ord($2).".$3");

@theVersionArray = split(/\./, $versiondata{$keyName});
for ($i = 0; $i < 3; $i++) {
if(!$theVersionArray[$i]) {
$theVersionArray[$i] = '0';
}
}

@versionArray = split(/\./, $version);

my $actualVersion;

for ($i = 0; $i < 3; $i++) {
if (($theVersionArray[$i] != $versionArray[$i]) or ($i == 2)) {

$actualVersion = $theVersionArray[$i];
$version = $versionArray[$i];

last;
}
}

my $expression = '$actualVersion ' . $operator . ' $version';
if( eval ($expression) )
{
return 1;
}
else
{
return 0;
}

}

__DATA__
/System/Library/CoreServices/Dock.app/Contents/MacOS/Dock
/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder
/System/Library/CoreServices/Automator Launcher.app/Contents/MacOS/Automator Launcher
/System/Library/CoreServices/Certificate Assistant.app/Contents/MacOS/Certificate Assistant
/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder
/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow
/System/Library/CoreServices/Network Setup Assistant.app/Contents/MacOS/Network Setup Assistant
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/MacOS/ARDAgent
/System/Library/CoreServices/SecurityAgent.app/Contents/MacOS/SecurityAgent
/System/Library/CoreServices/SystemUIServer.app/Contents/MacOS/SystemUIServer
/System/Library/PrivateFrameworks/ProKit.framework
/System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine
/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/QuartzComposer.framework/Versions/A/Resources/ExtraPatches.plugin/Contents/MacOS/ExtraPatches
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/SpeechSynthesis.framework/Versions/A/Resources/SpeechSynthesisServer.app/Contents/MacOS/SpeechSynthesisServer