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

Clipboard to photoshop text layer (.BAT to .TXT to .JSX) new line not being recognized

Explorer ,
Dec 20, 2023 Dec 20, 2023

New line or other object not being recognized by photoshop. Is there a good workaround for this? I assume I'll have to do str replace in the bat or photoshop. Is there a guide on what characters or new lines or other operative/invisible/special characters aren't accepted in photoshop? What syntax to use? People already said you couldn't paste into photoshop using scripting but I just did it (maybe they meant using only jsx), just need to fix formatting. Thanks for any help. 

Method: 
Copy html table from web, run jsx in photoshop.  

Result:
image.png


Bat file: 

@echo off
powershell -command "& {Get-Clipboard}" > "I:\output.txt"

Jsx file: 

// Function to execute a system command and capture its output
function executeCommand(command) {
  var fileObj = new File(command);
  fileObj.execute();
}

// Get clipboard data using the Batch script
var clipboardData = "";
try {
  executeCommand('I:\\RunPowershell.bat');
  
  // Read the output file
  var outputFile = new File('I:\\output.txt');
  outputFile.open('r');
  clipboardData = outputFile.read();
  outputFile.close();
  outputFile.remove();
} catch (e) {
  alert("Error executing Batch file: " + e);
}

// Create a new text layer in Photoshop
var textLayer = app.activeDocument.artLayers.add();
textLayer.kind = LayerKind.TEXT;
textLayer.textItem.contents = clipboardData;




TOPICS
Actions and scripting , Windows
318
Translate
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

correct answers 1 Correct answer

People's Champ , Dec 20, 2023 Dec 20, 2023

Try

clipboardData = clipboardData.replace(/\n/g, "\r");
Translate
Adobe
People's Champ ,
Dec 20, 2023 Dec 20, 2023

Try

clipboardData = clipboardData.replace(/\n/g, "\r");
Translate
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 ,
Dec 20, 2023 Dec 20, 2023
LATEST

Thanks, that worked perfect. I was using the wrong replace in a different version. 

updated for reference:

// Function to execute a system command and capture its output
function executeCommand(command) {
  var fileObj = new File(command);
  fileObj.execute();
}

// Get clipboard data using the Batch script
var clipboardData = "";
try {
  executeCommand('I:\\RunPowershell.bat');
  
  // Read the output file using advanced encoding
  var outputFile = new File('I:\\output.txt');
  outputFile.open('e', 'TEXT', '????');
  clipboardData = outputFile.read();
  outputFile.close();
  outputFile.remove();
  
  // Replace the special character with line breaks
  clipboardData = clipboardData.replace(/\n/g, "\r");
} catch (e) {
  alert("Error executing Batch file: " + e);
}

// Create a new text layer in Photoshop
var textLayer = app.activeDocument.artLayers.add();
textLayer.kind = LayerKind.TEXT;
textLayer.textItem.contents = clipboardData;



Translate
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