How do I find my Macs model from terminal?

Discussion in 'Mac Programming' started by glossywhite, Sep 5, 2009.

  1. glossywhite macrumors 65816

    glossywhite

    Joined:
    Feb 28, 2008
    #1
    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!!:

    Code:
    sysctl hw.model
     
  2. Guiyon macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #2
    try:

    Code:
    /usr/sbin/system_profiler SPHardwareDataType
    The information you want will be next to the "Model Identifier" key
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    Try this out,
    Code:
    system_profiler | grep "Model Id"
     
  4. Peace macrumors P6

    Peace

    Joined:
    Apr 1, 2005
    Location:
    Space--The ONLY Frontier
    #4
    Why use the terminal when it's right there in the system profile ? :confused:
     
  5. glossywhite thread starter macrumors 65816

    glossywhite

    Joined:
    Feb 28, 2008
    #5
    ... 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?:

    Code:
    #!/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
    
     

Share This Page