I posted a topic earlier about not being able to read the text in a popup button, but it turns out that that was not my problem. It turns out that I’m having trouble displaying information in a text field.
In a tutorial in Apple’s PDF “Building Applications With AppleScript Studio”, the following code is included:
tell window of theObject
try
set theRate to contents of text field "rate" as number
set theAmount to contents to text field "amount" as number
set contents of text field "total" to theRate * theAmount
on error
set contents of text field "total" to 0
end try
end tell
The important line, for me, was “set contents of text field “total”…”
For my application, I’m displaying information about computers in text fields. The user chooses a computer in a popup button, and I display information in four text fields. Here’s my code:
-- code to execute when user makes selection in list of computers
on action theObject
-- set the window
set theWindow to window of theObject
-- read the computer name from the popup menu
set computerDescription to title of current menu item of popup button "list_of_computers" of theWindow
-- display dialog or debugging purposes
display dialog "Computer Description: " & computerDescription buttons {"OK"} default button 1
-- determine which computer was selected
if computerDescription is equal to "Tobias Varland's Computer" then
--display dialog for debugging purposes
display dialog "computerDescription is equal to 'Tobias Varland's Computer'" buttons {"OK"} default button 1
-- set the properties
set computerName to "D58J5M11" as text
set workgroup to "VARLAND3" as text
set ipAddress to "199.5.82.67" as text
set theLocation to "Toby's Desk (Main Office)" as text
else if computerDescription is equal to "Ross Varland's Computer" then
--display dialog for debugging purposes
display dialog "computerDescription is equal to 'Ross Varland's Computer'" buttons {"OK"} default button 1
-- set the properties
set computerName to "D7SY720B" as text
set workgroup to "VARLAND3" as text
set ipAddress to "199.5.82.34" as text
set theLocation to "Ross' Desk (Production Office)" as text
else if computerDescription is equal to "Dan Rose's Computer" then
--display dialog for debugging purposes
display dialog "computerDescription is equal to 'Dan Rose's Computer'" buttons {"OK"} default button 1
-- set the properties
set computerName to "DCFP4J11" as text
set workgroup to "VARLAND3" as text
set ipAddress to "199.5.82.52" as text
set theLocation to "Dan's Desk (Main Office)" as text
end if
--display dialogs for debugging purposes
display dialog "Computer Name: " & computerName buttons {"OK"} default button 1
display dialog "Workgroup: " & workgroup buttons {"OK"} default button 1
display dialog "IP Address: " & ipAddress buttons {"OK"} default button 1
display dialog "Location: " & theLocation buttons {"OK"} default button 1
-- display the properties
tell theWindow
set contents of text field "computer_name" to computerName
set contents of text field "workgroup" to workgroup
set contents of text field "ip_address" to ipAddress
set contents of text field "location" to theLocation
end tell
end action
All of the “display dialog” commands work without a problem; they all display the correct information. The part of the code where I try to display the properties, though, does not work. Any suggestions?