Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 6, 2013, 04:34 PM   #1
h1068
macrumors newbie
 
Join Date: Jun 2012
Applescript: Inventory of local machine

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.

Quote:
Originally Posted by chown33 View Post
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 }' "

Last edited by h1068; Mar 8, 2013 at 09:08 PM. Reason: Resolved
h1068 is offline   0 Reply With Quote
Old Mar 6, 2013, 05:00 PM   #2
subsonix
macrumors 68040
 
Join Date: Feb 2008
Quote:
Originally Posted by h1068 View Post
What would i need to add in to just retrieve "H0021W0953333 as my output
You could try: | cut -d" " -f4 or | awk '{print $4}'

You would need to escape the quotes though.
subsonix is offline   0 Reply With Quote
Old Mar 6, 2013, 05:01 PM   #3
chown33
macrumors 603
 
Join Date: Aug 2009
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 }' "
chown33 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Local time machine backup of server dimme Mac OS X Server, Xserve, and Networking 2 May 21, 2014 06:09 PM
Fix file size of local time machine backup Paul E OS X 8 May 9, 2014 08:16 AM
Local Time Machine backups - will it auto delete? Risco OS X 10.8 Mountain Lion 3 Oct 2, 2013 01:48 PM
VNC issue - can't see 'local' cursor on networked machine? peanutismint OS X 0 Sep 10, 2013 08:22 PM
OS X with SSD&HDD Time Machine Local Snapshot haberland.it OS X 10.8 Mountain Lion 0 Jun 25, 2013 07:33 AM

Forum Jump

All times are GMT -5. The time now is 12:00 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC