Copy link to clipboard
Copied
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:
@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;
Try
clipboardData = clipboardData.replace(/\n/g, "\r");
Copy link to clipboard
Copied
Try
clipboardData = clipboardData.replace(/\n/g, "\r");
Copy link to clipboard
Copied
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;