Photoshop's "Place" command

I just thought I would ask if anyone knew of a workaround for trying to mimic Photoshop’s “Place” command.

I am using System events in this script to activate “Photoshop’s” Place command, which I assigned a keyboard shortcut.

After that stage, I always want an operator to browse to a particular file that will always be:
“Macintosh HD:Users:admin:Desktop:WorkInProgress:ExportedImage: ExportedImage.pdf”
After that they will scale the “Placed” art before accepting the change”this is why I have to use place vs. open.

I guess my question is, is it scriptable to have a file chosen from an already active Photoshop “Place” dialog window?

	tell application "Adobe Photoshop CS"
		with timeout of 300 seconds
			activate
			make new document with properties {height:103, width:155}
		end timeout
	end tell
	tell application "Adobe Photoshop CS"
		tell application "System Events" to keystroke "q" using {command down, control down, option down}
	end tell

Jeff,

Create an action in Photoshop using the “insert menu item” to call the Place… dialog.

Just call this action from your script…it’ll wait until the user resizes.

-N

Actually, I tried this method first with no success?
I found the best scenario is to use System Events to perform the Place command.
But. the issue I have is that I still have to browse to the paritcular file every time. I am searching for a way to always have the file selected, ready to be placed?

tell application "System Events"
		tell process "Adobe Photoshop CS"
			click menu item "Place..." of menu "File" of menu bar 1
			
		end tell
	end tell

Questions:

  1. Is the scale of the placed image consistant?
  2. What format is the placed image saved in?

If the scale is known, and it is a format that PhotoShop can open then you might want to have it open the file and copy the layer or layers over to the target document then close the soucre doucment without saving. This might take a bit more time, especially if PhotoShop needs to rasterize the file but you can set it so that it is dialog free. You might even be able to make a selection in the target document the size you need to scale it to and scale based on the pixel dimensions of that selection before copying it over to the new document. How accruate you can be with this depends on what the source file is and how it is built.

Jerome,
Unfortunately the scale of the placed image will not be consistent.

The format being placed will always be PDF.

I have tried other methods very similar to what you have mentioned. The problem is, I really need the ability to scale upon place, since I could never trust an operator to crop the selection to the text and/or graphics to the exact pixel bounds in InDesign, which is where it all begins.

The entire script is copying a selection in InDesign, pasting the selection to a new document that is 50 pts. larger than the selection (in order to account for text ascenders and descenders). That document is then exported as a PDF. - I tried the jpeg route, but pasted text frames within other frames, yielded issues. - PDF or EPS seemed the most consistent.

The entire script is below (please pardon my poor scripting):

tell application "InDesign CS"
	
	copy
	set sel to the selection
	set theDoc to active document
	set theName to "ExportedImage"
	set thePath to "Macintosh HD:Users:admin:Desktop:WorkInProgress:ExportedImage:"
	set filePath to thePath & theName & ".pdf"
	
end tell

set DocBounds to {0, 0, 0, 0}




tell application "InDesign CS"
	
	try
		set SelectionBounds to visible bounds of selection
		set DocBounds to SelectionBounds
		
		
		set DocHeight to ((item 3 of DocBounds) - (item 1 of DocBounds))
		set DocWidth to ((item 4 of DocBounds) - (item 2 of DocBounds))
		
		--return {DocHeight, DocWidth}
	end try
end tell

set DocBounds to {0, 0, 0, 0}



tell application "InDesign CS"
	try
		set SelectionBounds to visible bounds of selection
		repeat with i from 1 to count of SelectionBounds
			if DocBounds is {0, 0, 0, 0} then
				set DocBounds to item i of SelectionBounds
			else
				if item 1 of item i of SelectionBounds < item 1 of DocBounds then set item 1 of DocBounds to item 1 of item i of SelectionBounds
				if item 2 of item i of SelectionBounds < item 2 of DocBounds then set item 2 of DocBounds to item 2 of item i of SelectionBounds
				if item 3 of item i of SelectionBounds > item 3 of DocBounds then set item 3 of DocBounds to item 3 of item i of SelectionBounds
				if item 4 of item i of SelectionBounds > item 4 of DocBounds then set item 4 of DocBounds to item 4 of item i of SelectionBounds
			end if
		end repeat
		
		set DocHeight to ((item 3 of DocBounds) - (item 1 of DocBounds))
		set DocWidth to ((item 4 of DocBounds) - (item 2 of DocBounds))
		
	end try
end tell

--return {DocHeight, DocWidth}
if DocWidth is greater than DocHeight then
	tell application "InDesign CS"
		
		set theDoc to make document
		
		tell view preferences of theDoc
			set horizontal measurement units to points
			set vertical measurement units to points
			set ruler origin to page origin
		end tell
		tell document preferences of theDoc
			set properties to {page height:(DocHeight) + "50", page width:(DocWidth) + "50", page orientation:landscape, pages per document:1, column guide color:gray}
		end tell
		
		tell margin preferences of page 1 of theDoc
			set properties to {column count:1, column gutter:12, top:0, left:0, bottom:0, right:0}
			
		end tell
	end tell
end if
if DocWidth is less than or equal to DocHeight then
	tell application "InDesign CS"
		
		set theDoc to make document
		tell view preferences of theDoc
			set horizontal measurement units to points
			set vertical measurement units to points
			set ruler origin to page origin
		end tell
		tell document preferences of theDoc
			set properties to {page height:(DocHeight) + "50", page width:(DocWidth) + "50", page orientation:portrait, pages per document:1, column guide color:gray}
		end tell
		
		tell margin preferences of page 1 of theDoc
			set properties to {column count:1, column gutter:12, top:0, left:0, bottom:0, right:0}
		end tell
	end tell
end if



tell application "InDesign CS"
	
	paste
	
	export theDoc format PDF type to filePath without showing options
	close theDoc
	
	tell application "Adobe Photoshop CS"
		with timeout of 300 seconds
			activate
			make new document with properties {height:103, width:155}
		end timeout
	end tell
	tell application "System Events"
		tell process "Adobe Photoshop CS"
			click menu item "Place..." of menu "File" of menu bar 1
			
		end tell
	end tell
end tell

So, you have a :

  1. Variable size for the exported InDesign elements.
  2. Set size for the PhotoShop document size.

You should be able to rasterize the PDF upon opening it similar to this:

tell application "Adobe Photoshop CS"
	open alias "MyDisk:Users:jeromegantner:Desktop:Test.pdf" with options {page:1, constrain proportions:true, height:103, resolution:300, use antialias:true}
end tell

You might need to play around with the resolutioin and height properties a little to make sure that the resoltuion and size are correct for your use. You could then process this photoshop file as needed.

Jerome,
You never cease to amaze me, always providing excellent advice.

This works out very well, with one little addition”the use of the Trim command.

A couple things exist thanks to you. Now I won’t have to worry about an operator leaving empty space on the selected objects in InDesign. Trim will take care of those areas. And, like you suggest, I was able to hard code the rasterized PDF document size to 3 times as large as my final document size. So even with trimming, the document “should” never have to be resampled up to meet the required image size that follows in a subsequent action the makes the image 155 x 103. (That may be confusing, but it works)

This is GREAT!!!

Thank you so much for looking into this.

-jeff

	tell application "Adobe Photoshop CS"
		open alias "Macintosh HD:Users:admin:Desktop:WorkInProgress:ExportedImage.pdf" with options {page:1, constrain proportions:true, height:306, width:415, resolution:72, use antialias:true}
		try
			trim document 1 basing trim on transparent pixels
		end try
	end tell