• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: multi input form
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multi input form


  • Subject: Re: multi input form
  • From: red_menace <email@hidden>
  • Date: Mon, 08 Mar 2010 17:54:11 -0700


For a "pure" AppleScript solution, you can use the feature of a dialog box that
using returns in a default answer will let you use returns in the answer without
triggering the default button.

To actually use multiple input text fields you will need to use one of the other
recommended methods, but to just get multiple input items from the standard
display dialog you can use something like:


-- 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


Also see  http://macscripter.net/viewtopic.php?id=24707



On Mar 8, 2010, at 1:02 PM, Michele (Mike) Hjorleifsson wrote:

What is the best / easiest way to do a multi-field input form in applescript ?

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: multi input form
      • From: Deivy Petrescu <email@hidden>
  • Prev by Date: Re: multi input form
  • Next by Date: Re: multi input form
  • Previous by thread: Re: multi input form
  • Next by thread: Re: multi input form
  • Index(es):
    • Date
    • Thread