Displaying dialog with default answer words

Hello,

Here is part of my script I’m working on:

set currentName to (do shell script "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -getcomputername")

--Ask for computer name
set computername to text returned of (display dialog "Enter Computer Name" default answer word 3 of currentName)

The result of systemsetup -getcomputer name is Computer Name: COL-pgalla2-01I

I would like the default answer to be COL-pgalla2-01I but because of the hyphens, word 3 is only COL.
Is there a way to say something like: default answer words after 2? Basically just omit “Computer Name:” ?

Thanks.

hows this

set currentName to (do shell script "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -getcomputername | sed 's/^[^\\:]*: //g'")

--Ask for computer name
set computername to text returned of (display dialog "Enter Computer Name" default answer currentName)

Two more variants.

do shell script "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -getcomputername"
set currentName to text 16 thru -1 of result

set computername to text returned of (display dialog "Enter Computer Name" default answer currentName)

do shell script "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -getcomputername | /usr/bin/colrm 1 15"

set computername to text returned of (display dialog "Enter Computer Name" default answer result)

Thank you Kim and Bruce. They work great.

Just one or two additional points, patgmac.

If you’re interested in portability, the systemsetup file may not exist on every machine. For example, while I have a couple of similar files in ARDAgent’s contents (named systemsetup-jaguar and systemsetup-panther), there is no generic version.

To answer the part of your question about manipulating text, here’s one way of doing it with AppleScript:

set currentName to "Computer Name: COL-pgalla2-01I" as Unicode text (* purely to simulate your result *)
set computername to text returned of (display dialog "Enter Computer Name" default answer currentName's text from word 3 to -1)

So this works here:

set currentName to do shell script "system_profiler SPSoftwareDataType | grep 'Computer Name'"
set computername to text returned of (display dialog "Enter Computer Name" default answer currentName's text from word 3 to -1)

For more information about text and list manipulating techniques, you might like to read Nigel Garvey’s excellent article on Range References with AppleScript Text and Lists.

Here’s another (shorter and faster) way to get the computer name in Tiger:

set computername to text returned of (display dialog "Enter Computer Name" default answer (system info)'s computer name)

Thanks Kai. I really appreciate the other options. Gives me ideas for other things I would like to do as well.

This is part of a bigger script that I’m working on, the first thing it does is installs an ARD 3 client installer which does have a generic systemsetup command.

Here’s the entire script I have so far, this is to help us automate what we need to do on every Mac in our university.

--Install ARD 3.0 client. This needs to be installed first so the systemsetup command is installed
--The Lab version does not "Show status in menu bar" or "Show when being observed"
display dialog "Install ARD client for a Lab or Faculty/Staff?" buttons {"Lab", "F/S"} default button 2
if button returned of result is "F/S" then
	do shell script "installer -pkg /Volumes/MacSetup/Packages/ardFS.mpkg -target /" with administrator privileges
else
	if button returned of result is "Lab" then
		do shell script "installer -pkg /Volumes/MacSetup/Packages/ardLab.mpkg -target /" with administrator privileges
	end if
end if

set currentName to (do shell script "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -getcomputername | sed 's/^[^\\:]*: //g'")

--Ask for computer name
set computername to text returned of (display dialog "Enter Computer Name 

A=Mac Desktop 
i=Mac Laptop" default answer currentName)

--This sets the network time server, display sleep and computer name
do shell script "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setdisplaysleep 10 -setusingnetworktime on -setnetworktimeserver time.service.emory.edu setcomputername " & computername with administrator privileges
do shell script "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setlocalsubnetname " & computername with administrator privileges

--Turn on firewall, block UDP traffic, enable stealth mode and open ports for SAV
do shell script "/usr/bin/defaults write /Library/Preferences/com.apple.sharing.firewall state -bool YES" with administrator privileges
do shell script "/usr/bin/defaults write /Library/Preferences/com.apple.sharing.firewall stealthenabled  -int 1" with administrator privileges
do shell script "/usr/bin/defaults write /Library/Preferences/com.apple.sharing.firewall udpenabled  -int 1" with administrator privileges
do shell script "/usr/libexec/FirewallTool" with administrator privileges
do shell script "/usr/bin/defaults write /Library/Preferences/com.apple.sharing.firewall firewall -dict-add 'SAV' '<dict><key>editable</key><integer>0</integer><key>enable</key><integer>1</integer><key>port</key><array><string>2967</string></array><key>udpport</key><array><string>2967</string></array></dict>'" with administrator privileges

--Prevent .DS_Store files from being created on network shares. Needs to be done in 3 steps so it is applied to all users on the system
do shell script "/usr/bin/defaults write com.apple.desktopservices DSDontWriteNetworkStores true"
do shell script "/bin/mv ~/Library/Preferences/com.apple.desktopservices.plist /Library/Preferences/" with administrator privileges
do shell script "/bin/chmod 644 /Library/Preferences/com.apple.desktopservices.plist" with administrator privileges

--This will retrieve information about the computer using system_profiler. 
do shell script "system_profiler SPSoftwareDataType SPHardwareDataType > /Volumes/MacSetup/Reports/" & computername & ".txt"

--Reminder of what the computer name is
display dialog "Done with " & computername buttons {"Ok"} default button 1

--Items that can be checked off on the sweep sheet
display dialog "Check these items off on your sweep sheet:

Turned on firewall/UDP & Stealth
Opened SAV and allowed port 2967
Turned on ARD" buttons {"Ok"} default button 1

--Open the system_profiler report to help fill out the sweep sheet
tell application "TextEdit"
	open "MacSetup:Reports:" & computername & ".txt"
end tell