Skip to main content
Inspiring
December 20, 2023
해결됨

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

  • December 20, 2023
  • 1 답변
  • 503 조회

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:


Bat file: 

@4628292 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;




이 주제는 답변이 닫혔습니다.
최고의 답변: r-bin

Try

clipboardData = clipboardData.replace(/\n/g, "\r");

1 답변

r-bin답변
Legend
December 20, 2023

Try

clipboardData = clipboardData.replace(/\n/g, "\r");
Inspiring
December 20, 2023

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;