Skip to content

Instantly share code, notes, and snippets.

@anton-liubushkin
Created June 29, 2015 15:05
Show Gist options
  • Save anton-liubushkin/357075d9957e1f6f0ed2 to your computer and use it in GitHub Desktop.
Save anton-liubushkin/357075d9957e1f6f0ed2 to your computer and use it in GitHub Desktop.
Makes a rectangular selection — Photoshop script
// x, y, width, height
// x & y position from top left corner of document
// width & height of selection
//
// makeSelection(10,50,200,100);
function makeSelection(x,y,sw,sh){
app.activeDocument.selection.select([ [x,y], [x,y+sh], [x+sw,y+sh], [x+sw,y] ]);
}
@Michal0307
Copy link

Michal0307 commented Aug 28, 2019

extended version with units as parameter, because in my ps installation first script worked only with pixels (I needed in cm)

function makeSelection(x,y,sw,sh,strInUnit){ //makeSelection(x,y,sw,sh,"cm")
	var ysh=new UnitValue (parseFloat(y+sh), strInUnit);
	var xsw=new UnitValue (parseFloat(x+sw), strInUnit);
    app.activeDocument.selection.select([ [x,y], [x,ysh], [xsw,ysh], [xsw,y] ]);  
}

http://wereda.net

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment