-- multiple input dialog
on run -- example
set {firstName, lastName} to (inputItems for {"• First Name", "• Last Name"} with title given prompt:"Enter the following items separated by a carriage return:")
display dialog "First Name: \"" & firstName & "\"" & return & "Last Name: \"" & lastName & "\""
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:" & 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)
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