Quick query - Dialog director

AS: 1.6
MacOS: 9.2.2
iMac 600

What is the syntax for extracting text from a Dialog Director dialog box?
(Dialog Director scripting addition required)

I require a floating palette which is why DD is being used to generate the dialog box. I have been through a number of the example files but cannot find what I am looking for. I need to be able to assign the text entered into the Dialog box to a variable for later use.

Here is the dialog portion of the script:
property theDialog : {size:[260, 95], contents:[¬
{class:push button, bounds:[190, 65, 250, 85], name:“OK”}, ¬
{class:push button, bounds:[110, 65, 170, 85], name:“Cancel”}, ¬
{class:text field, bounds:[10, 36, 250, 36 + 16], name bounds:¬
[10, 10, 250, 26], name:“Please enter pdf file code”, value:“”}], style:movable dialog}

return [dd auto dialog theDialog with grayscale]

What is the command to now take the result and assign it to a variable?
Eg. set text returned to pdfCode ?? Display Dialog pdfCode ??

Hey Matt,

Here’s a possibility…

The result of the line

return [dd auto dialog theDialog with grayscale] 

is

{{true, false, "", {382, 347, 642, 442}}}

so the first thing you need to do is change the square braces for parentheses because you’re nesting a list inside a list, which is really just confusing things.

This gives you…

return (dd auto dialog theDialog with grayscale)

Which in turn will give the following result (as an example)…

{true, false, "Test text", {382, 347, 642, 442}}

From here you can use the following code…


set theDialogValues to dialogHandler()

set theText to item 3 of theDialogValues

--

on dialogHandler()
property theDialog : {size:[260, 95], contents:[¬ 
{class:push button, bounds:[190, 65, 250, 85], name:"OK"}, ¬ 
{class:push button, bounds:[110, 65, 170, 85], name:"Cancel"}, ¬ 
{class:text field, bounds:[10, 36, 250, 36 + 16], name bounds:¬ 
[10, 10, 250, 26], name:"Please enter pdf file code", value:""}], style:movable dialog} 

return (dd auto dialog theDialog with grayscale)
end dialogHandler

It’s worth looking at what actually gets returned from the handler. It gives the state of each of the buttons (a value of ‘true’ tells you which one was clicked), then the text which was entered, followed by the bounding rectangle of the dialog.

You can see from here that you want the third item of this list which is the text, so just set a variable to item 3 of the result. The order of the list is determined by the order in which you create the dialog items.

Hope this helps,

Juerg

PS. Does anyone know where Andreas has gone!? :cry:

No and I’ve been wondering the same. I think I’ll send a note to see what’s up. The BBS isn’t the same without Andreas. :slight_smile:

Good idea, Rob. Say ‘Hi!’ from me! :slight_smile:

Dear Juerg,

Thanks for your assistance.

[b]The section of code that you provided works just like I need it to. What I need to know is how to integrate this into my existing script that is already running a hander.

I get a message stating “expected end or end tell”. This indicates that either you can’t nest handlers or I’m not doing it correctly. [/b]

Here is the script that I am building, it is for batch renaming pdf files based on the information in the pdf file. The need for the floating dialog, is that sometimes the input dialog was obscuring the portion of the pdf file that contained the code that I required.

(take a any pdf and drag onto the app to run)
– assign global varibles
global pdfname
global origname
global timedelay

– set properties for the Dialog Director floating dialog box.
property theDialog : {size:[260, 95], contents:[¬
{class:push button, bounds:[190, 65, 250, 85], name:“OK”}, ¬
{class:push button, bounds:[110, 65, 170, 85], name:“Cancel”}, ¬
{class:text field, bounds:[10, 36, 250, 36 + 16], name bounds:¬
[10, 10, 250, 26], name:“Please enter pdf file code”, value:“”}], style:movable dialog}

– define variable for text returned out of dialog box.

set theDialogValues to dialogHandler()
set pdfname to item 3 of theDialogValues

on open fileList
–tell application “Finder”
–display dialog “How many seconds do you require to note the file code?” default answer “5”
–set timedelay to text returned of result
–close every window
– end tell

repeat with aFile in fileList
	tell application "Finder"
		activate
		set origname to name of aFile
		--display dialog origname
		open aFile
		-- delay 5
	end tell
	
	tell application "Finder"
		activate
		close every window
		[b]-- THIS IS THE PART THAT IS NOT WORKING.			
		on dialogHandler()
return (dd auto dialog theDialog with grayscale)

end dialogHandler[/b]
end tell

	tell application "Acrobat 5.0"
		activate
		close document origname
	end tell
	tell application "Finder"
		activate
		select aFile
		set name of aFile to pdfname & ".pdf"
	end tell
end repeat

end open[/b]

Hi Matt!

No problem!

I haven’t had time to test your script yet but here are a few observations…

The main problem here is that you can’t nest handlers which is why you’re getting the error when you try to compile your script. You must move the handler outside of the ‘on open()’ handler - so put it after the ‘end open’ statement.

However, having looked at your script I see no need for a handler. Try deleting the handler entirely and using this…

 set theDialogValues to (dd auto dialog theDialog with grayscale) 

instead of…

set theDialogValues to dialogHandler() 

Or perhaps even better, delete the following line aswell…

set pdfname to item 3 of theDialogValues

and use this…

set pdfname to item 3 of (dd auto dialog theDialog with grayscale)

I think this should get you going for now! :slight_smile:

All the best,

Juerg