I know how to get the current user name, but how can I get the current name of the machine, as found in the ‘sharing’ preference pane?
There are several ways, here’s a couple…
1)
do shell script "hostname"
do shell script "awk '/ComputerName/ " & "{{{getline} print substr($0,12,length($0)-20)} exit}'" & " /private/var/db/SystemConfiguration/preferences.xml"
Hostname is not (necessarily) the same as the sharing name as defined in the sharing pref pane. Code sample 2 should return the name as defined in the pref pane.
Jon
Thanks people. I did find after a little playing the hostname thing, but as said, thise seems to be the rendevouz name rather than the sharing name. I then also remembred about preferences.xml and so wrote a little script to read that file, but thanks to you I have a nice single line do shell script command. Thanks!
Actually, code sample 2 provides the Computer Name, not the Rendezvous name. (Usually it is the sharing name with spaces and other non-alphanumeric characters either omitted or changed to dashes) but all three, the Computer name, the Rendezvous name, and the Hostname, are all unique entities.
Jon
can you share it?
Bonjour name
set bonjour_name to do shell script "uname -n"
or, much easier but Tiger only
set bonjour_name to host name of (system info)
Computer name:
set computer_name to "grep -A1 'ComputerName<' /Library/Preferences/SystemConfiguration/preferences.plist | grep -v key | cut -f 2 -d '>' | cut -f 1 -d '<'"
or, much easier but Tiger only
set computer_name to computer name of (system info)
He’s talking about post #2.
I haven’t found where it’s kept, but GUI scripting works:
tell application "System Preferences" to reveal anchor "Main" of pane id "com.apple.preferences.sharing"
activate application "System Preferences"
tell application "System Events"
tell process "System Preferences" to tell window 1
click button 6
delay 0.5
set V to value of text field 1 of sheet 1
key code 53
end tell
end tell
tell V to set ShareName to text 1 thru ((my (offset of "." in it)) - 1) of V
tell application "System Preferences" to quit
Using StefanK and Adam’s scripts is this not the same thing?
set bonjour_name to (host name of (system info))
tell bonjour_name to set ShareName to text 1 thru ((my (offset of "." in it)) - 1) of bonjour_name
I confess to ignorance, Mark; I don’t know anything about Bonjour. :rolleyes:
Same here really, it just seems to be the same thing on my Mac?
Maybe this is of some interest…
set mySystemInfo to system info
returns
{AppleScript version:"1.10.7", AppleScript Studio version:"1.4.1", system version:"10.4.9", short user name:"xxxxx", long user name:"xxxx xxxx", user ID:501, user locale:"en_US", home directory:alias "Macintosh HD:Users:xxxxxx:", boot volume:"Macintosh HD", computer name:"CC's Macbook", host name:"CCs-Macbook.local", IPv4 address:"10.0.1.200", primary Ethernet address:"00:17:00:f0:84:be", CPU type:"Intel 80486", CPU speed:1990, physical memory:2048}
oops - didn’t realize Stefan already eluded to this…