Help with Dropdowns and Arrays

I am trying to make a drop down that gets the print presets from InDesign CS. So far the drop down gets the list but they are all in one line and not on separate lines like a drop down list should be.

Here is the code…

tell application "InDesign CS"
	set myDocument to active document
	set myDialog to make dialog
	set myPrintPresetList to (get name of every printer preset) as string
	tell myDialog
		set name to "Dialog Window"
		set myDialogColumn to make dialog column
		tell myDialogColumn
			set myBorderPanel to make border panel
			tell myBorderPanel
				set myDialogColumn to make dialog column
				tell myDialogColumn
					make static text with properties {static label:"Message:"}
				end tell
				set myDialogColumn to make dialog column
				tell myDialogColumn
					set myTextEditField to make text editbox with properties ¬
						{edit contents:"Hello Dude!", min width:180}
				end tell
			end tell
			set myBorderPanel to make border panel
			tell myBorderPanel
				set myDialogColumn to make dialog column
				tell myDialogColumn
					make static text with properties {static label:"Printer Preset:"}
				end tell
				set myDialogColumn to make dialog column
				tell myDialogColumn
					set myPrintPresetsField to make dropdown with properties {string list:{myPrintPresetList}, selected index:1, min width:180}
				end tell
			end tell
		end tell
	end tell
	set myResult to show myDialog
end tell


Ok I think this fixes it.

   set myPrintPresetList to (get name of every printer preset) as string 
   set myPrintPresetList to (get name of every printer preset) as list

now is there any one that can help me convert this from what looks like an “id” tag to an actual name for imstance “letter” if that was one of the presets?

I’m getting names not ID’s in the dropdown with your code.
I.e. result shows:
make with properties {string list:{“[Default]”, “My Printer Preset”, “Print Preset 1”, “_New”}, selected index:1, min width:180} new dropdown

Note that I had to modify the dropdown line to this to get it to work on my machine:
set myPrintPresetsField to make dropdown with properties {string list:myPrintPresetList, selected index:1, min width:180}
iolaire


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

iolaire

Yes my second post makes the change to as list instead of as string. I forgot to mention the removing of the brackets in the dropdown properties thanks for catching that.

I may have not been clear when I said I was getting ID’s…The dropdown does list the names i.e [default], Acrobat, Postscript, Blah, blah. It is the value that is returned I guess that I am trying to achieve I want to put the results from the drop down somewhere as the “Name” but I get…

get properties of printer preset {dropdown id 97841 of border panel id 97839 of dialog column id 97832 of dialog id 13478}

and that gives me this error…

"InDesign CS got an error: Invalid parameter.

So how do I turn the results from the dropdown into a text value not the ID

[I’m on OS X so this is not tested on 9] Thanks for asking about this, I’m new to CS and most of my scripts are faceless so its fun to work with user interaction!

This is working, but you can not see the string value in Script Editor’s result window. I’m duping it on the ID document so you can see that it is working correctly. iolaire


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Actually I’m on OS X as well I started this post in the wrong Forum “my Bad” :?

As far as the script goes I assume I need to set it as “real”

I am actually trying to get the selection to be used in the printer preset so that the use will not need to see the print dialog box.


--Here is another snippet..

	set myPrintPresetList to (get name of every printer preset) as list
--
tell myBorderPanel
				make static text with properties {static label:"Print Preset:"}
				set myPrintPreset to make dropdown with properties ¬
				{string list:myPrintPresetList, selected index:1, min width:180}
							end tell
--
 set myString to selected index of myPrintPreset as real
		set theProps to properties of printer preset myString
		set properties of print preferences of myDocument to theProps


I then get this error.

get selected index of dropdown id 97841 of border panel id 97839 of dialog column id 97832 of dialog id 13741
“Can’t make «class uiDi» of «class uiDD» id 97841 of «class uBdP» id 97839 of «class uiCW» id 97832 of «class uiDL» id 13741 of application “InDesign CS” into a real.”

I can confirm that the script posted above by iolaire works fine for me on Mac OS X 10.3.4/ID CS 3.0.1.

Jon

It looks as if you are getting the index of your selection then not using it to get the string that you have selected? You have the index so you need to reference the that index in your original list. But you need to add 1 to it as ID returns a zero based index, where as apple script is using a 1 based index?

This is your snippet rewritten to a form that should work.

--Here is another snippet.. 
   set myPrintPresetList to (get name of every printer preset) as list 
-- 
tell myBorderPanel 
            make static text with properties {static label:"Print Preset:"} 
            set myPrintPreset to make dropdown with properties ¬ 
            {string list:myPrintPresetList, selected index:1, min width:180} 
                     end tell 
-- 
	set myString to selected index of myPrintPreset as real
	set myString to myString + 1
	-- now get a string of what you have selected by the index
	set theProps to item myString of myPrintPresetList as string
	tell myDocument 
		set myPresetPrinter to theProps  -- name of print style picked
	end tell

Full working script, putting printer style picked in a new text frame and then printing:


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

iolaire

Thank you so much that did the trick. At first I couldn’t get it to do what I wanted then I realized I had “destroy myDialog” to soon in the script.

Again, thanks for your help.

Can you help with a page range situation I am having?
Currently I have every page being sent using the preset of my choice. How would i go about telling Indesign to only print a specific page/s separated by “,” and/or a range of pages separated by “-”. Also not every document starts at 1, but they all contain a text box with auto numbering character.

You have to set your print preferences’ PageRange. I believe will only accept numbers or numbers separated by a minus sign, so 1 or 1-2 will work but not 1,3. So if you want to print various pages you will probably have to do multiple print commands.

As to your pages numbered by some sort of box get the document offset of that box or it’s parent to get the true page number to to print.

If you are just trying to print all you could do checkbox and if it is checked do a loop printing from 1 to the total number of pages in the document?

I’d recommend hard coding your page number variables to start and get that working, then try creating a loop that loops through printing some pages. Once you get the code working tie that into your dialog box.

So once you get hard coded and printing all pages working you will need to find a way to take your comma separated values and change those into a list? It seems like a fairly common need.

Then you can could loop through the list from item 1 to the last item and print those ranges. Maybe you can find an example on these forms where an string is converted to a list or an array? Then just count the items in that list or array and loop through them.
iolaire

iolaire

Indeed you can type in a comma or hyphen. The commas will send separate pages wher e the hypen will send a range. So typing 1,5-7,10,4 will print pages 1,4,5,6,7,10. However I am wanting separate postsript files. That is why I needed the print preset drop down, I have a preset that will save .ps files. So I want a script that will send one page at a time through that preset, in order to get separate .ps files of every page saves with myPrefixName + PageNumber + “.ps”. As I have it right now the script will send all the pages. This is all fine but I get stories with 100+ pages and I don’t want to have to go back and delete unwanted .ps files.

thanks

Ken

I have found a way to get the name of every document…


	set myDocumentRange to (get name of every page of myDocument) as list

This is a start now I need to get the user input and check the numbers against each other and if they don’t match up give the user an error.

Ok. so I am using this line of code to search the pages in a document…


set myDocumentRange to (get name of every page of myDocument) as list 

I get this back {“3”,“4”,“5”,“8”,“10”}.

I can make a drop down with this info.


set myPageRangeField to make dropdown with properties {string list:myDocumentRange, selected index:0, min width:180}

But how do I have this string placed in the as the edit contents text editbox?

 
set myDocumentRangeString to (myDocumentRange as string)
set myPageRangeField to make text editbox with properties {edit contents:myDocumentRangeString, min width:180}

I turn it into a sting, do I have to? I keep getting 345810 put in it but i want 3,4,5,8,10 instead.

Also if I want a user to type in a string lets say they type in 3,8,4,9,10.-basically numbers separated by commas. How do i make it decend in order lowest to highest so that I can check it against the string myDocumentRange, so that an alert pops us telling the user the pages do not mach because of the"9"?

Where can I find some information on working with data? Is this basic stuff? I know I can look though the messages (and I have looked high and low) to pick up things here and there but learning this way seems really slow. Any tips or good resources?

Thanks 8)