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

Paste text from clipboard to textItem

Engaged ,
Jan 12, 2023 Jan 12, 2023

Copy link to clipboard

Copied

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');

 

TOPICS
Actions and scripting

Views

912

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

correct answers 2 Correct answers

Guide , Jan 16, 2023 Jan 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) {
    
...

Votes

Translate

Translate
Guide , Jan 25, 2023 Jan 25, 2023

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

 

 
 

 

 

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 15, 2023 Jan 15, 2023

Copy link to clipboard

Copied

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 , …? 

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
Guide ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

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
}

 

 

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 ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

As so often: Impressive! 

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
Engaged ,
Jan 24, 2023 Jan 24, 2023

Copy link to clipboard

Copied

Ah, perfect!

Thank you!

(Sorry for my late reply!)

Regards!

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
Engaged ,
Jan 24, 2023 Jan 24, 2023

Copy link to clipboard

Copied

Something strange is happening.

Trying to explain...

I use the script to set environment variable, to open a network path, containing utf-8 characters

When my network path variable comes from right click at Windows explorer address bar using "copy address as text" and pasted   at my script prompt using ctrl + v, manually from keyboard, the folder open 

Using the script for filling the prompt, the folder is not opening

 The text seems identical in both cases.

 

First script to set the path

(At script prompt, replacing the s using ctrl+v works fine)

 

#target photoshop

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()


var SetPath = prompt("Paste folder path", s);
var SetPath2 = SetPath.replace(/['"]+/g, '')
$.setenv("myFolder_doc_env" ,SetPath2);

 

Second script to open the path

 

#target photoshop
var myFolder_doc = $.getenv("myFolder_doc_env")
var myNewFolderFromEnvVar = new Folder (myFolder_doc);
myNewFolderFromEnvVar.execute();

 

 

Example path

\\server2_2\sync\Πίνακες&κάδρα\Sunflowers, Van Gogh 25818\

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
Guide ,
Jan 24, 2023 Jan 24, 2023

Copy link to clipboard

Copied

try this:

 

#target photoshop

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,-1):c.WriteLine(t):c.Close';
f.open("w");
f.encoding = "UTF8";
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()


var SetPath = prompt("Paste folder path", s);
var SetPath2 = SetPath.replace(/['"]+/g, '')
$.setenv("myFolder_doc_env", encodeURI(SetPath2));

 

(added UTF8 markers and converted folder name with unicode characters to URI)

 
 

 

 

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
Engaged ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

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

Same behavior

Ctrl + v works, using script 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
Guide ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

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

 

 
 

 

 

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
Engaged ,
Jan 25, 2023 Jan 25, 2023

Copy link to clipboard

Copied

LATEST

Works like a charm, thank you!

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