Skip to main content
Participant
September 4, 2008
Question

How to paste clipboard text into a text layer?

  • September 4, 2008
  • 5 replies
  • 3809 views
My client has asked me to help them script some PS actions. Their need is to take a text file, extract line by line, create a PS document that contains the text of a given line, run some actions/filters on it, and save it.

I have an AppleScript that takes the master text file and loops over every line in the file. For each iteration, I copy the the line of text to the clipboard. I have recorded PS Actions that create a new document, create a text layer, paste the clipboard text into the text layer, and then continues on applying the filters et al.

Creating the document and creating the text layer are no problem. Pasting the text from the clipboard has been a huge problem. PS simply won't paste. It complains "The command "Paste" is not currently available." I think it's wrong, since before I ran that action, I looked at the Edit menu, and Paste certainly was enabled and selectable. The text in the text layer was highlighted/selected, and I'm able to paste manually. So why can't PS paste automatically?

I have a "Make" action, which makes the document. I have a "Make Text Layer" action that creates the text layer in that document; this leaves the "boilerplate" placeholder text selected, such that a subsequent Paste operation would overwrite it with the contents of the clipboard. But this is what PS refuses to do. I've tried it from a PS action, and I've tried it using the 'paste' command in an Applescript; both result in the aforementioned error.

I think I need it to be a text layer, because subsequent steps change the font, size, apply various filters to it. We tried converting the text lines to PDF files, but weren't able to modify the text then.

Any ideas?

Thanks.
randy
This topic has been closed for replies.

5 replies

Participant
November 13, 2008
bingo. You rock. I even emailed AppleScript guru sal.

Thanks

Karl
Known Participant
November 12, 2008
Kark, you do not require "current document" in your save statement you are already inside a current document tell block "Dof_Ref" is your current document. You are trying to save current doc of current doc so to speak. Outside of the "tell Doc_Ref" this line would work.
This works for me

-- Flexible path to the current user's desktop & folder
set My_Folder to (path to desktop as Unicode text) & "test:"
-- Let user select file of choice
set The_Text to choose file with prompt ¬
"(make sure the correct layer is selected) Where is the text file?" without invisibles
-- Read the file
set Layer_Text to read The_Text
-- Create a variable list of the paragraphs
set Layer_List to paragraphs of Layer_Text as list
-- Process the list in Photoshop
tell application "Adobe Photoshop CS2"
activate
set Doc_Ref to the current document
tell Doc_Ref
-- Only need to do this the once
set My_Options to {class:JPEG save options, quality:12}
-- Loop through the paragraphs
repeat with This_Text in Layer_List
set Text_Layer to current layer
set Text_Item to text object of Text_Layer
set contents of contents of Text_Item to This_Text
set My_File to My_Folder & "card-" & This_Text & ".jpg"
save in file My_File as JPEG with options ¬
My_Options appending no extension with copying
end repeat
end tell -- current document
end tell -- application "Adobe Photoshop CS2
Participant
November 11, 2008
Ug, I'm going crazy. I GOT THIS TO WORK, then when I closed it, I didn't save the last bug fix I figured out, and I reopened it a day later, got the same bug and can't remember what I dd to fix it.

I need to stripe in serial numbers onto a psd file and save individual images. I blew through this and it cranked out 1000 images from the text file it read.

NOW, when I do it, it chokes on the path to the file and says "File/folder" expected. BUT when I pull the save code into another script, it does generate the JPEG and save it where it should.

Here's the code:

-- THIS SCRIPT PROMPTS YOU FOR A TEXT FILE, THEN REPLACES THE CURRENT TEXT LAYER WITH EACH LINE OF THE FILE, AND SAVES AS A JPG TO THE DESKTOP/TEST FOLDER THAT YOU NEED TO MAKE SURE EXISTS

-- Let user select file of choice
set The_Text to choose file with prompt "(make sure the correct layer is selected) Where is the text file?" without invisibles

-- Read the file
set Layer_Text to read The_Text
-- Create a variable list of the paragraphs
set Layer_List to paragraphs of Layer_Text as list
-- Process the list in Photoshop
tell application "Adobe Photoshop CS3"
activate
set Doc_Ref to current document
tell Doc_Ref
-- Loop through the paragraphs
repeat with This_Text in Layer_List
set Text_Layer to current layer
set Text_Item to text object of Text_Layer
set contents of contents of Text_Item to This_Text
set myFile to "Macintosh HD:Users:karlmessner:Desktop:test:card-" & This_Text & ".jpg"
set myOptions to {class:JPEG save options, quality:12}

save current document in file myFile as JPEG with options ¬
myOptions appending no extension with copying
end repeat
end tell
end tell
Known Participant
September 5, 2008
Randy, I would have AppleScript do everything except apply the layer styles (no access well not in CS2). Using paste from the clipboard is the last way I would go about trying this. Instead make a variable list from your paragraphs then have Photoshop process this list placing the text of the variable straight into the contents of the text item. No clipboard required at all safer too. This should give you the general idea. My actions for each are named "Action Style Text 1", "Action Style Text 2" & "Action Style Text 3" and are in a set called "Marks Text Styles"

-- Let user select file of choice
set The_Text to choose file with prompt "Where is the text file?" without invisibles
-- Read the file
set Layer_Text to read The_Text
-- Create a variable list of the paragraphs
set Layer_List to paragraphs of Layer_Text as list
-- Process the list in Photoshop
tell application "Adobe Photoshop CS2"
activate
-- Use to currnet document
set Doc_Ref to the current document
tell Doc_Ref
-- Use to first text style
set The_Style to 1
-- Loop through the paragraphs
repeat with This_Text in Layer_List
set Text_Layer to make new art layer at beginning with properties {kind:text layer}
set Text_Item to text object of Text_Layer
set font of Text_Item to "ArialMT"
set size of Text_Item to 72
set stroke color of Text_Item to {class:RGB color, red:255, green:0, blue:0}
set position of contents of Text_Item to {400, 400}
-- Here is how to add your text to the layer
set contents of contents of Text_Item to This_Text
try
do action "Action Style Text " & The_Style from "Marks Text Styles"
end try
-- Set to use the next style on next paragraph
set The_Style to The_Style + 1
end repeat
end tell
end tell
try67
Community Expert
Community Expert
September 5, 2008
Hi Randy,

I've recently developed a JavaScript tool that does something very similar to what you're looking for. Contact me by email (click my username for the address), and we can discuss it.

Cheers, try67.