Flipping object or selection in Photoshop CS3

Is there any way to flip an object or selection in Photoshop using Applescript? I see that there is a flip canvas command, but I do not want to flip the entire canvas. I only want to flip the contents of a selected area of a layer. Thanks.

Okay… I figured out how to do this, the long-ish way. Using the flip canvas command, I copy the selection area I want to flip, make a new document, paste the selection in the new document, flip canvas, select all and copy, close new document without saving, paste flipped image into the original document selection area. Not very elegant… but it works.

I’m not sure why you are asking how to do this on a Applescript forum?

But you only need to make your selection and under the Edit Menu, go to the Transform sub menu and the select a flip option.
This will only flip the selection.

There is no need to automate this with Applescript, again you can do this with the CS menus. Using the Actions (look under windows menu) and the Automate menu in file Menu.

Well, the desire to flip an object is only part of a larger script… I am combining parts and pieces from two different image documents, in order to make a print file an for odd-shaped banner. Basically, I am trying to automate a process that takes a lot of time doing it manually. Perhaps it would have been just as well to use Actions within Photoshop.

Alternatively, you could use a bit of Script Listener code.


You could give this a try. It’s script listener it ‘should’ do the following:
Flip an ‘art layer’ or selection of art layer Horizontally or Vertically.
It will flip a selection of background layer as is, but fail if background is ‘true’ and there is no selection.
It will flip a smart object layer but not a selection of one.
It will fail if your selection is empty.

tell application "Adobe Photoshop CS2"
	set Doc_Ref to the current document
	tell Doc_Ref
		-- Set the target layer of choice
		set current layer to layer 1
		-- Check its background is false so it can be flipped
		if background layer of current layer is true then
			set background layer of current layer to false
		end if
		my Flip_HV(Doc_Ref, horizontal)
	end tell
end tell

on Flip_HV(Doc_Ref, H_or_V)
	tell application "Adobe Photoshop CS2"
		if H_or_V is vertical then set H_or_V to "Vrtc"
		if H_or_V is horizontal then set H_or_V to "Hrzn"
		tell Doc_Ref
			do javascript "Flip_HV(); function Flip_HV() {function cTID(s) { return app.charIDToTypeID(s); }; function sTID(s) { return app.stringIDToTypeID(s); }; var desc01 = new ActionDescriptor(); var ref01 = new ActionReference(); ref01.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') ); desc01.putReference( cTID('null'), ref01 ); desc01.putEnumerated( cTID('Axis'), cTID('Ornt'), cTID('" & H_or_V & "') ); executeAction( cTID('Flip'), desc01, DialogModes.NO ); };" show debugger on runtime error
		end tell
	end tell
end Flip_HV

Hey – Thank you all very much! I appreciate all of your help and input. I will give the Script Listener a try. It may be that the paste-to-a-new-document routine is sufficient for my needs right now. I was just surprised that such a basic action as flipping a selection in PS was not an available option for AS.

If you have the selection you can always use System Events:

tell application "Adobe Photoshop CS3"
	delay 1
	tell application "System Events"
		pick menu item "Flip Horizontal" of menu "Transform" of menu item "Transform" of menu "Edit" of menu bar item "Edit" of menu bar 1 of process "Adobe Photoshop CS3"
	end tell
end tell

It is weird that that fundtion is not in PhotoShop’s scripting dictionary.

Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)

That works very nicely. I was not aware of “System Events”. The only minor down side to this is making sure whatever machine is running the script has “Enable access for assitive devices” checked in their System Prefs. But, since it would only be used on a couple machines here at work, that would not be a major problem. Thanks again!