List returned from display dialog

Is there a way to get a list from the text returned by a user?


set inset_answer to text returned of (display dialog "Enter the Inset Numbers" default answer "000")

The user will enter in a string of numbers (123,15,453,7)

I need to break those numbers into a list that I can use as a repeat fuction later in the script.

Thanks

fishheadtw,

You could do something like this:

set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set theList to {}
set inset_answer to text returned of (display dialog "Enter the Inset Numbers" default answer "000")
repeat with i from 1 to 4
set theList's end to text item i of inset_answer
end repeat
set AppleScript's text item delimiters to tid

I have not tried this script, but I think it’s correct. The repeat is assuming that every answer returned by the user is four numbers separated by commas.

PreTech

Thanks PreTech,
It is getting closer, but the user responds
can be a string of any numbers not just 4.
I was trying something like this but was unable to get
each number by itself. it was giving it to me
as a string of numbers.


tell application "Finder"
		activate
		set tid to AppleScript's text item delimiters
		set AppleScript's text item delimiters to ","
		set theList to {}
		set inset_answer to text returned of (display dialog "Enter the Inset Numbers" default answer "000")
		repeat with i from 1 to count of inset_answer
			set theList's end to text item i of inset_answer
			
		end repeat
		set AppleScript's text item delimiters to tid


Thanks

fishheadtw,

Try this:

set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set theList to {}
set inset_answer to text returned of (display dialog "Enter the Inset Numbers" default answer "000")
repeat with i from 1 to (count every text item of inset_answer)
	set theList's end to text item i of inset_answer
end repeat
repeat with anItem in theList
	display dialog anItem as string
end repeat
set AppleScript's text item delimiters to tid

The display dialog is just to make sure the list is correct.

PreTech

fishheadtw:

Here’s a thought…


set inset_answer to (words of text returned of (display dialog "Enter the Inset Numbers" & return & return  & "Follow your number with the Return Key." & return  & "Press Enter when finished" default answer "000" & return & return & return & return & return))

This requires using the Return Key for entering data instead of commas. Unfortunately, you can’t scroll back up to check your numbers, but I like to try to get the most out of one-liners as I can.

Just a thought.

Jim Neumann
BLUEFROG

Slick, Jim. You can scroll back, however - the up arrow key will move up the stack and the right arrow key will move among the digits. Both forward and back delete work as well (all this in 10.4.6)

Thanks for the kudos, Adam. I do stand corrected (here in the forgotten lands of 10.3.9). You can do all the moving around as you said. It’d be nice if there was a scroll bar though.:confused:

BTW, for anyone reading this… You can vary them amount of returns at the end to give yourself a longer or shorter default answer space BUT YOU MUST HAVE AT LEAST TWO or the Return Key will function as the default button.

Enjoy,
Jim Neumann
BLUEFROG

You might also want to check out the topic: A single dialog to handle multiple entries.

I subsequently modified the multi_dialog handler to iron out the differences in behaviour between Panther and Tiger. Since I can’t seem to edit the article now (and in case anyone’s interested), I’ll post the revised code here:

on multi_dialog for q given listing:l
	tell q as list
		set {a, b, c} to {{}, beginning, count}
		set v to b's class is integer
		if v then set {c, v, q} to {b, b is 0, rest}
	end tell
	if v then set c to 30
	repeat c + 1 div (1 + (system attribute "sysv") div 4160) times
		set a's end to ""
	end repeat
	set {d, text item delimiters} to {text item delimiters, return}
	set {q, a, text item delimiters} to {q as string, a as string, d}
	set r to (display dialog q default answer a)'s text returned
	if not v then tell r & a
		if l then return items 1 thru c of paragraphs
		if c > 1 then return text 1 thru paragraph c
	end tell
	tell r to repeat with i from (count paragraphs) to 1 by -1
		if (count paragraph i) is not 0 then
			if l then return paragraphs 1 thru i
			return text 1 thru paragraph i
		end if
	end repeat
	if l then return {}
	""
end multi_dialog

------------------
-- demonstration --
------------------

property l : {"1]  Name: {items: 2, length: fixed, output: list}", ¬
	"2]  Address: {items: 3, length: fixed, output: list}", ¬
	"3]  Reasons: {items: 6, length: fixed, output: list}", ¬
	"4]  ToDo List: {items: ?, length: variable, output: text}", ¬
	"5]  Standard: {items: 1, length: variable, output: text}"}

property d : l's item 1

tell (choose from list l default items d with prompt "Choose a multi-dialog demonstration:")
	if it is false then error number -128
	set d to it
	set i to item 1's item 1 as integer
end tell

--------------------
-- syntax examples --
--------------------

if i is 1 then
	multi_dialog for {"¢ What is your first name?", "¢ And your last name?"} with listing
else if i is 2 then
	multi_dialog for {3, "Please enter your:", "", "1: house number & street name", "2: city/area", "3: zip code"} with listing
else if i is 3 then
	multi_dialog for {6, "List up to six reasons to be cheerful:"} with listing
else if i is 4 then
	multi_dialog for {0, "To Do list for " & (current date)'s weekday & ":"} with listing
else
	multi_dialog for "Did you *really* just want a standard dialog?" without listing
end if

That’s true in Panther, Jim - but a single return does the trick in Tiger.