• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

I need a script to create a new file with double the dimensions and 144dpi in photoshop 2023

Explorer ,
Jun 01, 2023 Jun 01, 2023

Copy link to clipboard

Copied

I tried to use AI to create a script to create a new 144 dpi file in Photoshop 2023 from the clipboard image, with twice the dimensions. It generated the following code.

// This is a Photoshop script that creates a new document from the clipboard with double the dimensions and 144 dpi resolution
// Save this file as a .jsx extension and place it in the Photoshop 2023/Presets/Scripts folder
// Restart Photoshop and run the script from File > Scripts > Create New File From Clipboard

// Check if there is something in the clipboard
if (app.clipboard.hasData()) {
  // Get the clipboard data as a bitmap
  var clipboardData = app.clipboard.getData("bitmap");
  // Get the width and height of the bitmap in pixels
  var width = clipboardData.width;
  var height = clipboardData.height;
  // Double the width and height
  width *= 2;
  height *= 2;
  // Create a new document with the doubled dimensions and 144 dpi resolution
  var newDoc = app.documents.add(width, height, 144);
  // Paste the clipboard data into the new document
  newDoc.paste();
  // Resize the pasted layer to fit the document
  newDoc.activeLayer.resize(200,200);
  // Rename the new document
  newDoc.name = "New File From Clipboard";
} else {
  // Alert the user that there is nothing in the clipboard to paste
  alert("There is nothing in the clipboard to paste.");
}


It fails, gives me the following error.
Screen Shot 2023-06-01 at 12.52.01 PM.png 

Any idea to make it work? Apparently app.clipboard.hasData() is not finding the clipboard's data.

TOPICS
Actions and scripting , macOS

Views

445

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
People's Champ ,
Jun 01, 2023 Jun 01, 2023

Copy link to clipboard

Copied

Have your AI enumerate the properties and methods of the Application object in the Photoshop Object Model. And also let it give a link to the source of information. Then tell it to find the error in its code itself.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2023 Jun 01, 2023

Copy link to clipboard

Copied

quote

Have your AI enumerate the properties and methods of the Application object in the Photoshop Object Model. And also let it give a link to the source of information. Then tell it to find the error in its code itself.


By @r-bin

 

Thanks for the laugh, I needed that!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2023 Jun 01, 2023

Copy link to clipboard

Copied

@renatoj93608056 â€“ Do you really need to use the clipboard, why not just dupe the active doc?

 

dupeDoc(activeDocument.name.replace(/\.[^\.]+$/, '') + "_x2", false);
imageSize(200, 200, 144);

function dupeDoc(docName, merged) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putEnumerated(s2t("document"), s2t("ordinal"), s2t("first"));
	descriptor.putReference(s2t("null"), reference);
	descriptor.putString(s2t("name"), docName);
	descriptor.putBoolean(s2t("merged"), merged);
	descriptor.putInteger(s2t("documentID"), 867);
	executeAction(s2t("duplicate"), descriptor, DialogModes.NO);
}

function imageSize(width, height, resolution) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	descriptor.putUnitDouble(s2t("width"), s2t("percentUnit"), width);
	descriptor.putUnitDouble(s2t("height"), s2t("percentUnit"), height);
	descriptor.putUnitDouble(s2t("resolution"), s2t("densityUnit"), resolution);
	descriptor.putEnumerated(s2t("interfaceIconFrameDimmed"), s2t("interpolationType"), s2t("nearestNeighbor"));
	executeAction(s2t("imageSize"), descriptor, DialogModes.NO);
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 02, 2023 Jun 02, 2023

Copy link to clipboard

Copied

Maybe I should have mentioned that I was trying to get Photoshop 2023 to do with a script what Photoshop CS did by default: I would copy an image from InDesign or Sketch, start a new file in Photoshop CS, set it to 144 dpi and the interface would automatically double the dimensions of the image in the clipboard. Any time I would do that afterwards, it would retain the 144 dpi setting and I would just paste the image in the new file window. Now repeat that several times a day in the post-CS versions and you will see how much time and brain power was saved then. But now that you mentioned it, I tried to just change the default resolution after the new file is created and Outlook 2023 automatically doubles the dimensions, when I was expecting it to require me to double the dimensions manually as when creating a new file. So, that's good enough for me. Not yet, AI...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 02, 2023 Jun 02, 2023

Copy link to clipboard

Copied

quote

Maybe I should have mentioned that I was trying to get Photoshop 2023 to do


By @renatoj93608056


That is generally helpful...

 

Yes, it's possible to do this as suggested by @r-bin using actions or scripting listener recorded code if you can't script.

 

You can use the clipboard code from the following link to replace the dupeDoc function and call in my previous code:

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 02, 2023 Jun 02, 2023

Copy link to clipboard

Copied

Stephen_A_Marsh

 

All your similar links are blocked by antivirus.

https://prepression.blogspot.com/2021/10/photoshop-script-events-manager.html

 

vir.jpg

Translation:

Redirection to a site that poses a risk of data loss is prevented

Stopped going to a phishing or fake site designed to trick you into entering passwords, credit card details, or other personal information.

Kaspersky Lab has protected you from accessing this site.

You can close it without risk.

Discovered: 06/03/2023 03:42:52 Web address: https://prepression.blogspot.com/2021/10%3C...%3E

 

Blocked by: Web Anti-Virus

Reason: threat of data loss

Detection method: bases

 

I understand the risk and want to go to the site

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 02, 2023 Jun 02, 2023

Copy link to clipboard

Copied

LATEST

@r-bin

 

Thank you for the notice, it appears to be an invalid Krapersky issue.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 01, 2023 Jun 01, 2023

Copy link to clipboard

Copied

double_clip.jpg

the scriptlistener will help you create the script code if that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines