choose from list -- don't want choices

I am not a trained AppleScriptor. My knowledge is limited to hacking other people’s code.

I am trying to create a simple list using the Run AppleScript action in Automator where no choice is made. You just look at it and click Exit to leave. I have resorted to using “choose from list” leaving one of the buttons and the title an prompt blank.

on run {input, parameters}

set myList to input
choose from list myList with title "" with prompt "" default items "myList" OK button name "Exit" cancel button name "" with empty selection allowed

return input

end run

This is close, but I would like to get rid of the extraneous, blank button. Choose from list probably isn’t the way to do this but I don’t really know what is!

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.18.5
Operating System: Mac OS X (10.6)

Hi,

choose from list displays always two buttons.
If the list is not too long use just display dialog


on run {input, parameters}
	copy input to myList
	set {TID, text item delimiters} to {text item delimiters, return}
	display dialog (myList as text) buttons {"Exit"} default button 1
	set text item delimiters to TID
	return input
end run

or “abuse” the default answer parameter


on run {input, parameters}
	copy input to myList
	set {TID, text item delimiters} to {text item delimiters, return}
	display dialog "" default answer (myList as text) buttons {"Exit"} default button 1
	set text item delimiters to TID
	return input
end run

Display dialog isn’t the answer. That was the first thing I tried. I guess I should have said that. My apologies.

Display dialog only provides four lines. One test query produced a 15 line list, which was why I abandoned display dialog in favor of choose from list. I need to handle any number of lines. It could be one or 20. The nice thing about choose from list is it adjusts the width and number of lines to the input list. I’m not sure what happens if the number of lines grows too large. Maybe it puts up a scroll bar.

You may want to try Stefan’s first posted solution before dismissing it. There is no four line limitation; display dialog can present at least 40 lines before things start to leave the screen. The TID’s create line breaks and the dialog elongates to that length.

the second solution works, too. There is no scroll bar, but you can scroll in the “list” with the normal text field shortcuts.

You’re right. I didn’t realize that. However, between having to scroll beyond four lines and having a blank button but a full panel, choose from list is closer to what I need.

Is there any way to get rid of that blank button?

on run {input, parameters}
	copy input to myList
	set {TID, text item delimiters} to {text item delimiters, return}
	set theMessage to myList as text
	set text item delimiters to TID
	display alert "" message theMessage
	return input
end run

Mind the empty string between ‘alert’ and ‘message’.

Fantastic! However, it raises another trade-off. Choose from list dynamically adjusts the box size to fit. Display alert uses a fixed width and long lines wrap. Also, the extraneous button is now replaced with the word “Alert.” However, this one is much cleaner.

One thing, it appears display covers a family of arguments, dialog and alert, so far. Are there others I can try?

Sorry 'bout that. Nothing we can do, here.
There should be one button named “OK”. What do you get when you run it from the AppleScript Editor?

set myList to {1, 2, 3, 4, 5, 6, 7}
set {TID, text item delimiters} to {text item delimiters, return}
set theMessage to myList as text
set text item delimiters to TID
display alert "" message theMessage

They are both in Standard Additions’ dictionary (Window>Library in the editor). There are no others, AFAIK.

That script works fine, except for the word wrap. I don’t know why Alert shows at the top when you run it from Automator because it seems to be identical.

At this point it looks like I need to decide between word wrap in one case and an extraneous button in the other.

Thanks, everybody for your help. I’ve learned a little more about AppleScript.