Resolved Applescript: Inventory of local machine

Discussion in 'Mac Programming' started by h1068, Mar 6, 2013.

  1. h1068, Mar 6, 2013
    Last edited: Mar 8, 2013

    macrumors newbie

    Joined:
    Jun 10, 2012
    #1
    Hello, Im using this script to get the serial number of my machine.

    Code:
    set sys to do shell script "/usr/sbin/system_profiler SPHardwareDataType " without altering line endings
    
    set StringVariable1 to "Serial"
    
    set Serial_Number to (do shell script "echo \"" & sys & "\" | grep \"" & StringVariable1 & "\"") as text
    
    Output: Hardware Overview:

    Model Name: iMac
    Model Identifier: iMac9,1
    Processor Name: Intel Core 2 Duo
    Processor Speed: 2.26 GHz
    Number Of Processors: 1
    Total Number Of Cores: 2
    L2 Cache: 3 MB
    Memory: 4 GB
    Bus Speed: 1.07 GHz
    Boot ROM Version: IM91.008D.B08
    SMC Version (system): 1.44f0
    Serial Number (system): H0021W0953333

    \" | grep \"Serial\""
    end tell
    Result:
    " Serial Number (system): H0021W0953333"




    What would i need to add in to just retrieve "H0021W0953333 as my output, instead of " Serial Number (system): H0021W0953333"

    Thanks


    Resolved: Thank you chown33, this worked for me.

     
  2. macrumors 68040

    Joined:
    Feb 2, 2008
    #2
    You could try: | cut -d" " -f4 or | awk '{print $4}'

    You would need to escape the quotes though.
     
  3. macrumors 603

    Joined:
    Aug 9, 2009
    #3
    Replace your multiline AppleScript code with this one line:
    Code:
    set Serial_Number to do shell script "/usr/sbin/system_profiler SPHardwareDataType | awk '/Serial/ { print $NF }' " 
    
     

Share This Page