Drag and Drop from AppleScript Studio App to InDesign CS2

I’m having some difficulty with Drag and Drop.

I’m creating an app in AppleScript Studio where I have a text field with a path to a PDF file.

I want to be able to select that path and drag it into an InDesign document, thus placing the PDF file. The best I’ve been able to achieve is to drag the actual text of the path from AS Studio App into InDesign, which then creates a text box with the text in it, but so far I haven’t been able to place the file.

Any thoughts or ideas would be greatly appreciated.

Thanks.

boswellian,

You could try putting a button next to your text box and when the user clicks the button it places the PDF of the path in InDesign. Does your PDF file have multiple pages? Is there a specific page that the PDF needs to be place on? (i.e. active page, or specific).

If you choose to go this route your code could be something like:


on clicked theObject
if name of theObject is "PDF_PLACE_BUTTON" then
	set PDF_PATH to contents of text field "PATH_TEXT" of window of theObject as alias
	tell application "Adobe InDesign CS2"
		activate
		set page number of PDF place preferences to 1
		tell document 1
			set MY_PLACED_PDF to place PDF_PATH on page 1
		end tell
	end tell
end if
end clicked

CarbonQuark

CarbonQuark,
The PDFs that are being placed are single page Ads. The idea is that the user could drag and drop them into an InDesign layout wherever they wanted to put them.

I was actually planning to implement a drag and drop and a push button method. I’ve done this with RealBasic in the past. With RB, you can specify that the drag object be a file, so when dragging into InDesign, it behaves as if you were dragging a file from the finder, and if the file is an appropriate image, InDesign with place it on the page.

I thought that setting the drag types to “file” would accomplish the same thing, but so far no such luck. I’ll have to read through the documentation again.

Boswellian,

assuming your text field is:

  • not editable/selectable
  • contains a POSIX path of the pdf file

then you could subclass NSTextField and add these lines in the .m file of your subclass:

- (void)mouseDown:(NSEvent *)theEvent{ NSString *path = [self stringValue]; if (! [path isEqual:@""]) { [self dragFile:path fromRect:[self frame] slideBack:NO event:nil]; } [super mouseDown]; }
set this subclass as custom class for your text field in Interface Builder. Now a drag from the textfield drags the file instead of the string.

Hope that helps.

D.

Dominik,
That worked perfectly! Thanks for the help.

-Boswellian