Skip to main content
Inspiring
January 13, 2023
Answered

Paste text from clipboard to textItem

  • January 13, 2023
  • 2 replies
  • 1484 views

Hi!

I want to paste text from windows clipboard to a new textItem

Pseudo code

 var layers = app.activeDocument.artLayers;
        var layer = layers.add();
        layer.kind = LayerKind.TEXT;
        var textItem = layer.textItem;
        textItem.kind = TextType.PARAGRAPHTEXT;
        textItem.size = 30;
        textItem.position = [10, 10];
        textItem.contents = activeDocument.paste();

It is possible to Photoshop ?

 

This works at illustrator

 var doc = app.activeDocument;
var _newTextFrame = doc.textFrames.add();
_newTextFrame.contents = 'Test';
_newTextFrame.textRange.select();
app.executeMenuCommand('paste');

 

This topic has been closed for replies.
Correct answer jazz-y

Thank you for your efforts, but it doesn't work

Same behavior

Ctrl + v works, using script no ...


try to change

 

$.setenv("myFolder_doc_env", encodeURI(SetPath2));

 

to

 

$.setenv("myFolder_doc_env", encodeURI(SetPath).replace(/\%0A$/,''));

 

* originally I thought we were talking about copying plain text. When you specified that we are talking about file paths, I did not take into account that when we read a file, we get a line feed character at the end of the line. In Windows this is not critical for local paths, but is important for network paths

 

 
 

 

 

2 replies

Legend
January 16, 2023

Windows:

 

var f = new File(Folder.temp + '/script.vbs'),
    s = 'Set o = CreateObject("htmlfile"):t = o.ParentWindow.ClipboardData.GetData("text"):f=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%TEMP%") & "\\clipboard.txt":set c = CreateObject("Scripting.FileSystemObject").OpenTextFile(f, 2, True):c.WriteLine(t):c.Close';
f.open("w");
f.encoding = "TEXT";
f.write(s);
f.close()
f.execute()
$.sleep(500)
var c = new File(Folder.temp + '/clipboard.txt'),
    s = '';
if (c.exists) {
    c.open("r");
    s = c.read();
    c.close()
}
f.remove()
c.remove()
if (s != '') {
    var layers = app.activeDocument.artLayers;
    var layer = layers.add();
    layer.kind = LayerKind.TEXT;
    var textItem = layer.textItem;
    textItem.kind = TextType.PARAGRAPHTEXT;
    textItem.size = 30;
    textItem.position = [10, 10];
    textItem.contents = s
}

 

 

c.pfaffenbichler
Community Expert
Community Expert
January 16, 2023

As so often: Impressive! 

c.pfaffenbichler
Community Expert
Community Expert
January 16, 2023

I am afraid you may need to use a work-around utilizing VB; I am a Mac-user myself so hopefully someone else can offer more insight – @jazz-y , @r-bin , @Kukurykus , …?