To reproduce what I'm looking to do with scripting (JSX) in Photoshop:

  1. Select part of image with transperant background (no background layer)
  2. Copy
  3. File -> New *1
  4. Paste

*1 - Photoshop will then automatically crop your selection to the boundaries of your image and use that as widht & height, how can I get this information through scripting in JSX?

I've managed to get the layer size boundaries, but that's not what I want. I want to get the size from whats on the clipboard.

EDIT - I looked through all of the docs, and figured out that you get an ArtLayer when pasting - I could then get the bounds of this artlayer and crop the image. Incase anyone else needs it I put my working script here: https://gist.github.com/amaeland/49f84bb14c76c35e825f

  • Is your canvas a > custom canvas ? or > clipboard Feb 9, 2016 at 5:43
  • 1
    The other option would've been to use app.activeDocument.trim( TrimType.TRANSPARENT );, which doesn't require you to know the layer size.
    – Joonas
    Feb 9, 2016 at 14:11
  • @Joonas : Thanks! always good to know about alternatives, ill keep the method I have for now since it enables me to customise stuff like add padding etc.
    – am_
    Feb 9, 2016 at 16:50

2 Answers 2


Honestly this answer depends on your version of Photoshop, but I'm going to assume you're working with the most recent version.

Luckily the newest version (CC 2015) has some built-in clipboard interactions, which you can read up on here.

If this isn't what you need, then I suggest to keep looking through that document. If nothing turns up it may not be very exposed for you to find at which point you may have more luck getting the height and width another way and then trying to insert it yourself into the new document dialog.

If you have a different version of Photoshop, check the documentation here (CS2-CC 2015.)


I use AppleScript to script Photoshop, not JavaScript, but hopefully this solution will still work for you.

To get the size of the image that is on the clipboard, create a new Photoshop document — it will be created at the size of what is on the clipboard — and then get the width and height of the new document, and then close the new document without saving.

  • Thanks for the comment, I'll look into that - when creating a new document with Javascript it does not use the clipboard preset.
    – am_
    Feb 9, 2016 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.