Re: Getting Mac OS X's Ethernet Address/Hostname via AppleScript
Re: Getting Mac OS X's Ethernet Address/Hostname via AppleScript
- Subject: Re: Getting Mac OS X's Ethernet Address/Hostname via AppleScript
- From: Christopher Nebel <email@hidden>
- Date: Thu, 31 Jan 2002 15:54:35 -0800
On Wednesday, January 30, 2002, at 03:33 PM, Richard Glaser wrote:
How can you get the the "Ethernet Address" and "Hostname" for Mac OS X
10.1.2 via AppleScript. I need these items to automate renaming ByHost
folder filenames to correspond to cloned machine...
In the absence of a proper AppleScript way to get them, "do shell
script" is your friend. (A possibly surly and unpleasant one, depending
on your background, but a friend nonetheless.)
To get the host name:
do shell script "/bin/hostname"
To get the hardware address of the built-in Ethernet adapter:
do shell script "/sbin/ifconfig en0 | grep ether | cut -d' ' -f 2"
Beware that "do shell script" behaves slightly differently in
AppleScript 1.8.2 (still in beta, but publicly available) -- it leaves
the output of the command completely alone, so you may need to trim off
a trailing line-feed character. 1.8.1 attempts to be helpful and trim
it for you, but that can cause problems in certain situations. A simple
workaround compatible with either is to follow up "do shell script" with
"get paragraph 1 of the result".
--Chris Nebel
AppleScript Engineering