Multiple entries by user in display dialog?

Looking to prompt a user of an applescript to enter two variables in that I will then export to Excel. Can I display a dialog box that prompts the user for two pieces of data? I've heard of Applescript studio or something like that name...is this more in that realm? Here is the script I have so far for prompting the user for the info, except that it is a series of dialog boxes. Looking to make it concise and have all the info entered at once.

<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #FFDDFF;
overflow: auto;"
title="this text can be pasted into the Script Editor">
set slots to {"A", "B", "C", "D", "E", "F"}
set rooms to {"1 ", "2", "3", "4", "5", "6", "7", "8", "9", "10"}
set chosenslot to (choose from list slots with prompt "What slot does your first class go into? Choose one." without multiple selections allowed) as text
if chosenslot is not "false" then
display dialog "You chose " & chosenslot & ". Next choose the course to go into this slot"
set chosencourse to (choose from list rooms with prompt "What course will go into slot " & chosenslot & "? Choose one." without multiple selections allowed) as text
display dialog "So " & chosenslot & " will be put into " & chosencourse & " CORRECT??"</pre>


dan

2 GHz Mac Book, Mac OS X (10.5.7)

Posted on Jun 13, 2009 4:23 PM

Reply
4 replies

Jun 13, 2009 4:53 PM in response to Dan Erlandson

Display dialogs can only accept a single string value, but if you prompt your user to use a separator, you can process that string into the data values that you want, like this:


set a to text returned of (display dialog "Please enter the slot (A-F) and the course (1-10), separating them with a comma:" default answer "")
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set {chosenslot, chosencourse} to {(a's text item 1), (a's text item 2)}
set AppleScript's text item delimiters to astid


Good luck,

Jun 13, 2009 7:22 PM in response to Dan Erlandson

If the default answer of a dialog contains a return, then you can +use a return in the answer+ (in this case, the return key won't be used for the default button, although the enter key will still be used). Going a little bit further than casdvm, but using the same idea (using a return as a delimiter between items), you can fake a multiple input dialog. I have a general purpose handler that will get multiple input items (it is a bit long but has a lot of options):

<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px; height: 340px;
color: #000000;
background-color: #FFEE80;
overflow: auto;"
title="this text can be pasted into the Script Editor">
on run -- example
set {Slot, Course} to (InputItems for {"• Class slot", "• Course"} with Prompt given Title:"Data Entry")

display dialog "Slot: " & (quoted form of Slot) & return & "Course: " & (quoted form of Course) with title "results"
end run


to InputItems for SomeItems given Title:TheTitle, Prompt:ThePrompt
(*
displays a dialog for multiple item entry - a carriage return is used between each input item
for each item in SomeItems, a line of text is displayed in the dialog and a line is reserved for the input
the number of items returned are padded or truncated to match the number of items in SomeItems
to fit the size of the dialog, items should be limited in length (~30) and number (~15)
parameters - SomeItems [list/integer]: a list or count of items to get from the dialog
TheTitle [boolean/text]: use a default or the given dialog title
ThePrompt [boolean/text]: use a default or the given prompt text
returns [list]: a list of the input items
*)
if ThePrompt is in {true, false} then -- "with" or "without" prompt
if ThePrompt then
set ThePrompt to "Input the following items separated by returns:" & return & return -- default
else
set ThePrompt to ""
end if
else -- fix up the prompt a bit
set ThePrompt to ThePrompt & return & return
end if

if TheTitle is in {true, false} then if TheTitle then -- "with" or "without" title
set TheTitle to "Multiple Input Dialog" -- default
else
set TheTitle to ""
end if

if class of SomeItems is integer then -- no item list
set {TheCount, SomeItems} to {SomeItems, ""}
if ThePrompt is not "" then set ThePrompt to text 1 thru -2 of ThePrompt
else
set TheCount to (count SomeItems)
end if
if TheCount is less than 1 then error "InputItems handler: empty input list"
set {TheItems, TheInput} to {{}, {}}

repeat TheCount times -- set the number of lines in the input
set the end of TheInput to ""
end repeat
set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set {SomeItems, TheInput} to {SomeItems as text, TheInput as text}
set AppleScript's text item delimiters to TempTID

set TheInput to paragraphs of text returned of (display dialog ThePrompt & SomeItems with title TheTitle default answer TheInput) -- with icon caution with hidden answer)

repeat with AnItem from 1 to TheCount -- pad/truncate entered items
try
set the end of TheItems to (item AnItem of TheInput)
on error
set the end of TheItems to ""
end try
end repeat
return TheItems
end InputItems
</pre>

If you are looking at easier error handling or an entry box for each item, then yes, AppleScript Studio is what you want.

Message was edited by: red_menace

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Multiple entries by user in display dialog?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.