determine local system name

I need (if possible) to find out the name (i.e., the Computer Name in the Sharing system preference panel) of the computer the script is running on:

set mycomputername to “? what goes here ?”
if mycomputername is “whatever” then
do something

any ideas?

Thanks!

have you tried scripting the GUI

using the ui scripting

Not yet. I was hoping to grab it directly as I’m not that familiar with scripting the GUI.

According to this entry by Jonathan Nathan, this should do it. It works for me on OS X 10.2.8.

set mycomputername to do shell script "grep APPLETALK_HOSTNAME /etc/hostconfig | cut -d '=' -f 2"

– Rob

Sweet! That did the trick.

Thanks!

that should do quite nicely it worked for me as well

here is the code to but it in string

set computer_name to do shell script "grep APPLETALK_HOSTNAME /etc/hostconfig | cut -d '=' -f 2"
set computer_name to hex_to_string((text 2 thru -2 of computer_name) as string)


on hex_to_string(this_string)
	set return_string to ""
	repeat with i from 1 to length of this_string by 252
		try
			set return_string to return_string & (run script "«data cstr" & (text i thru (i + 251) of this_string) & "00» as string")
		on error
			set return_string to return_string & (run script "«data cstr" & text i thru -1 of this_string & "00» as string")
		end try
	end repeat
	return return_string
end hex_to_string

I saw that note but mine is returned as a string. I wonder why the difference. [OS X 10.2.8 here]

– Rob

i am using 10.2.8 as well and mine came up as hex

maybe some user pref somewhere along the line shrug
well we figured it out anyway thanks to jonathon nathan

How about this…

do shell script "uname -a | awk '/.local/{print $2}'"

the only difference i see is the punctuation and spaces

but who cares unless you need it

but it does seem simpler

Or this, (not sure who to credit for the first one)

do shell script "awk '/ComputerName/ " & "{{{getline} print substr($0,12,length($0)-20)} exit}'" & " /private/var/db/SystemConfiguration/preferences.xml"

Or with Extra Suites

tell application "Extra Suites" to computer name of («event OXENSYSO»)

or

do shell script "hostname"