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');
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) {
...
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
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 , …?
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
}
Copy link to clipboard
Copied
As so often: Impressive!
Copy link to clipboard
Copied
Ah, perfect!
Thank you!
(Sorry for my late reply!)
Regards!
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\
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)
Copy link to clipboard
Copied
Thank you for your efforts, but it doesn't work
Same behavior
Ctrl + v works, using script no ...
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
Copy link to clipboard
Copied
Works like a charm, thank you!