|
|
#1 |
|
Prospect
Join Date: Sep 2002
Posts: 5
|
applescript "computer name" command problem OS X
I'm runnning OS 10.2.4 and I'm trying to get the applescript below to work
set moo to computer name display dialog moo it is supposed to pop up with a dialog that has the computer's name in it. It works fine in macOS 9 and classic but fails in macOS X... MacOS X script editor changes the program to set moo to system attribute name display dialog moo Then fails giving some sort of UNIX environment variables in the error box. I am curious if this is a bug in MacOS X or some sort of bizzar intended behavior I can't follow... |
|
|
|
|
|
#2 |
|
Triple-A Player
Join Date: Jan 2002
Posts: 179
|
Try using the do shell script functionality:
set moo to do shell script "grep APPLETALK_HOSTNAME /etc/hostconfig | cut -d '=' -f 2" display dialog moo |
|
|
|
|
|
#3 | |||||||||||||||||||
|
Prospect
Join Date: Sep 2002
Posts: 5
|
no, that doesn't work.. My hostconfig file doens't have my machine name in it... |
|||||||||||||||||||
|
|
|
|
|
#4 |
|
All Star
Join Date: Jan 2002
Location: Dexter, MI, USA
Posts: 704
|
If I do
Code:
set moo to do shell script "hostname" display dialog moo The other script works for me though, so this is possibly no help at all if your hostname is set to something different than what the UNIX part of your computer thinks it is (if that's possible)
__________________
- Greg Happy user of OS X since the Public Beta. Help Team Mac OS X cure cancer, Alzheimer's, ALS, Parkinson's, and more! |
|
|
|
|
|
#5 | |||||||||||||||||||
|
Triple-A Player
Join Date: Jan 2002
Posts: 179
|
Hmmm. That's worked on all the machines I've tried it on. (As does Greg's.) What result do you get when you run them? |
|||||||||||||||||||
|
|
|
|
|
#6 | |||||||||||||||||||
|
Prospect
Join Date: Sep 2002
Posts: 5
|
I just get a bunch of numbers.. i think I may have worked out why, though.. If you put a none-standard char in it (like option g), the name gets set to a bunch of numbers... There are other problems with greping the hostconfig file.. If you have a double quote, the double quote will be escaped (that is it will have a backslash in front)... Actually, I'm quite impressed, the logic for figuring out what to put in the hostconfig file form the computer's name must be fairly complex.. ! Oddly enough, I think the default name generated when the user first uses their system has a smart single quote in it.. Which is asking for trouble.... Greping the hostconfig file is not a universal solution. The hostname command trick works.... however it's not the computer's name, it's the rendezvous name... |
|||||||||||||||||||
|
|
|
|
|
#7 |
|
All Star
Join Date: Jan 2002
Location: Dexter, MI, USA
Posts: 704
|
This will work assuming you have no period in your computer name:
Code:
set moo to do shell script "hostname | awk -F. '{print $1}'"
display dialog moo
__________________
- Greg Happy user of OS X since the Public Beta. Help Team Mac OS X cure cancer, Alzheimer's, ALS, Parkinson's, and more! |
|
|
|
|
|
#8 | |||||||||||||||||||
|
Prospect
Join Date: Sep 2002
Posts: 5
|
Code:
set moo to do shell script "hostname -s" display dialog moo of course it's still the rendezvous name, which can be varied independently fom the computer name, but anyways... At least it's not a large seemingly random number. I wonder if I should bother with a bug report on how Code:
display dialog computer name
Code:
display dialog system attribute name |
|||||||||||||||||||
|
|
|
|
|
#9 |
|
League Commissioner
Join Date: Jan 2002
Posts: 5,536
|
% man hostname
... -s Trims off any domain information from the printed name. |
|
|
|
|
|
#10 |
|
Prospect
Join Date: Jul 2002
Posts: 14
|
The only way I know to return the computer name is using 'Extra Suites' from www.kanzu.com then you can run this script.
Code:
tell application "Extra Suites" to computer name of (system info) MacScripter.net |
|
|
|
|
|
#11 |
|
Registered User
Join Date: Dec 2004
Posts: 1
|
shell command to pull computer name
The computer name is located in the file /Library/Preferences/SystemConfiguration/preferences.plist .
One shell command (can run in Terminal) to print the computer name is grep -A1 'ComputerName<' /Library/Preferences/SystemConfiguration/preferences.plist | grep -v key | sed s/"[[:blank:]]*<\/*string>"//g It has to be all on one line. This looks for the string "ComputerName<" and returns that line and the one after it, removes the line containing the word "key", and then strips off the leading whitespace and the <string></string> tags around the actual computer name. I'm sure there are other prettier ways to parse the information from the preferences.plist file as well. |
|
|
|
|
|
#12 |
|
Prospect
Join Date: Jun 2009
Posts: 1
|
I wanted to add to this thread that scutil can get you a clean Computer Name regardless of the state of the network.
scutil --get ComputerName I have found that both scutil and hostname are useful when writing network scripts. Be aware that hostname can change if you are using DHCP depending on your Location setting and which network you are on. As an example here is a useful Perls scrip that will let you know of your desktop or laptop is connected to the network if you are using DHCP. Code:
#!/usr/bin/perl
# Checks to see of network location is active by verifying DHCP has
# given the Macintosh a useable host name.
# Loop network check
while (1) {
# Get dhcp hostname given to the system
$hostname = `hostname`;
# Get the Machintosh Computer Name
$macname = `scutil --get ComputerName`;
# Remove line returns
chomp $hostname;
chomp $macname;
# Check if the host name is <Computer Name>.local
# If it is, the Macintosh has not been assigned a DHCP hostname
if ($hostname eq "${macname}.local") {
print "$hostname $macname NETWORK IS DISABLED\n";
}
else {
print "$hostname $macname network is active\n";
}
# Sleep for two seconds before repeting loop
sleep(2);
}
|
|
|
|
|
|
#13 |
|
Triple-A Player
Join Date: Aug 2003
Posts: 132
|
What's wrong with
display dialog computer name of (system info) ? No shell script, no "Extra Suites"...not sexy enough? ![]() Just noticed the date of the thread...um, never mind.
__________________
***************** ** homo sapien ** *** emulation *** **** wetware **** ***************** Last edited by robot_guy; 06-18-2009 at 09:42 PM. Reason: Oh...I see... |
|
|
|
![]() |
|
|