• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting Mac OS X's Ethernet Address/Hostname via AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Getting Mac OS X's Ethernet Address/Hostname via AppleScript (From: Richard Glaser <email@hidden>)

  • Prev by Date: Re: Week of year - odd/even week
  • Next by Date: Re: Scripting Additions: Embracing the Horror of Unix
  • Previous by thread: Re: Getting Mac OS X's Ethernet Address/Hostname via AppleScript
  • Next by thread: finding reference to spread of generic box in QuarkXPress
  • Index(es):
    • Date
    • Thread