copying text to the clipboard

Anyone, especially newbies, asking for help with photoshop scripting and photoshop automation - as opposed to those contributing to discussion about an aspect of photoshop scripting

Moderators: Patrick, Mike Hale, xbytor, Larry Ligon, Andrew, PS-Moderators

copying text to the clipboard

Postby Bruce83 » Mon Dec 21, 2009 2:39 pm

Hi.
I'm trying to copy a text/string to the windows clipboard inside a photoshop script. I want it to be in the clipboard so I can past it in another applikation using ctrl+v. Is there any way to do that. I have been trying for several hours now but couldn't figure it out.

I'm using Photoshop CS3, Javascript and Windows XP.

I hope someone can help me.

Best regards,
Bruce
Bruce83
 
Posts: 8
Joined: Wed Jun 25, 2008 3:18 pm
Location: Germany, Erlangen

Postby Paul MR » Mon Dec 21, 2009 3:01 pm

The only way I know of doing this is using VBS and IE...

Code: Select all
var str="This is my string for the clipboard";
var tempFile = File("~/desktop/TempVBS.vbs");
tempFile.open('w');
tempFile.writeln('set ie=createobject("internetExplorer.application")');
tempFile.writeln('ie.navigate "about:blank"');
tempFile.writeln('do until ie.readystate=4: wscript.sleep 1: loop');
tempFile.writeln('ie.document.parentwindow.clipboardData.setData "Text"," '+str+'"');
tempFile.close();
tempFile.execute();
Paul MR
 
Posts: 1472
Joined: Wed Oct 18, 2006 2:44 pm
Location: Bradford,UK

Postby Paul MR » Sat Jan 02, 2010 11:37 pm

Just found another way, this relies on a util existing that is installed with office "clip.exe" if you have this you can do the following...
Code: Select all
var clipFile =new File(Folder.temp + "/ClipBoard.bat");
clipFile.open('e');
clipFile.writeln("echo yes this text is for the clipboard|clip");
clipFile.close();
clipFile.execute();
Paul MR
 
Posts: 1472
Joined: Wed Oct 18, 2006 2:44 pm
Location: Bradford,UK

Postby Bruce83 » Thu Jan 07, 2010 8:05 am

Thank you very much Paul. This works great. :wink:
Bruce83
 
Posts: 8
Joined: Wed Jun 25, 2008 3:18 pm
Location: Germany, Erlangen

Postby Paul MR » Fri Jan 08, 2010 9:25 am

If you require a "paste" you can find one here..
http://huddledmasses.org/clipexe-and-th ... -pasteexe/

This is useful to direct the clipboard to a file so that it can be accessed.
Paul MR
 
Posts: 1472
Joined: Wed Oct 18, 2006 2:44 pm
Location: Bradford,UK

Postby Bruce83 » Fri Jan 08, 2010 10:14 am

I used the methode described by Paul and put it in a function.
I had to extend it because it didn't work with texts that contained spaces or special character like '|'. In the first step I create a textfile with the text that I want to copy. In the second step I copy the contents of this text file to the clipboard. This works even if there are spaces or line breaks in the text.

Code: Select all
function copyTextToClipboard(text)
{
   var folderForTempFiles = Folder.temp.fsName;
   
   // create a new textfile and put the text into it
   var clipTxtFile =new File(folderForTempFiles + "/ClipBoard.txt");
   clipTxtFile.open('w');
   clipTxtFile.write(text);
   clipTxtFile.close();
   
   // use the clip.exe to copy the contents of the textfile to the windows clipboard
   var clipBatFile =new File(folderForTempFiles + "/ClipBoard.bat");
   clipBatFile.open('w');
   clipBatFile.writeln("cat \"" + folderForTempFiles + "/ClipBoard.txt\"|clip");
   clipBatFile.close();
   clipBatFile.execute();
}
Bruce83
 
Posts: 8
Joined: Wed Jun 25, 2008 3:18 pm
Location: Germany, Erlangen

Re: copying text to the clipboard

Postby mtemp » Mon May 31, 2010 1:34 pm

I had to change one line of script:

Code: Select all
clipBatFile.writeln("clip.exe < \"" + folderForTempFiles + "\\ClipBoard.txt\"");


Vista64 (Office 2003)


Very useful! Thanks!
mtemp
 
Posts: 1
Joined: Mon May 31, 2010 12:53 pm

Re: copying text to the clipboard

Postby larsen67 » Tue Jun 01, 2010 10:58 am

set the clipboard to "Foo"

a mac (appleScript) alternative…
larsen67
 
Posts: 445
Joined: Sat Apr 25, 2009 3:01 pm
Location: Pickmere, Cheshire UK


Return to Help Me

Who is online

Users browsing this forum: No registered users and 2 guests