PDA

View Full Version : applescript with Photshop text layers




troyman11
Mar 15, 2013, 03:49 PM
Hello,
I was wondering how to edit text layers in adobe photoshop via applescript. I am trying to create multiple input boxes and paste the text from the applescript to a photoshop Text Layer. For example, I ask for an input of "Last Name" in applescript and want the text layer to paste the "last name" in photshop to the edited Last Name text layer.
I am very new too applescript so I would appreicate if the community can point me in the right direction.

display dialog "Last Name?" default answer "Last Name"
set theanswer to (text returned of result)
display dialog theanswer
tell application "Adobe Photoshop CS5"
set current layer to "Last Name"
clear layer "Last Name"
paste theanswer to "Last Name"
end tell



sero
Mar 15, 2013, 06:22 PM
not really sure what you're trying to do but you could probably get it done using imagemagick.

kryten2
Mar 16, 2013, 03:14 PM
Hello,
I was wondering how to edit text layers in adobe photoshop via applescript. I am trying to create multiple input boxes and paste the text from the applescript to a photoshop Text Layer. For example, I ask for an input of "Last Name" in applescript and want the text layer to paste the "last name" in photshop to the edited Last Name text layer.
I am very new too applescript so I would appreicate if the community can point me in the right direction.

display dialog "Last Name?" default answer "Last Name"
set theanswer to (text returned of result)
display dialog theanswer
tell application "Adobe Photoshop CS5"
set current layer to "Last Name"
clear layer "Last Name"
paste theanswer to "Last Name"
end tell

Perhaps this will get you started. Also take a look at the scripting dictionary of Photoshop.

set firstName to text returned of (display dialog "First Name" default answer "Bill" buttons {"OK"} default button 1)
set lastName to text returned of (display dialog "Last Name" default answer "Gates" buttons {"OK"} default button 1)
-- Change tell application line below to your version of Photoshop
tell application "Adobe Photoshop CS6"
--set theLayers to every art layer of current document
--get properties of art layer 1 of current document
--set kind of art layer 1 of current document to text layer
--set kind of art layer 2 of current document to text layer
--get properties of text object of art layer 1 of current document
get contents of text object of art layer 1 of current document
get contents of text object of art layer 2 of current document
set contents of text object of art layer 1 of current document to lastName
set contents of text object of art layer 2 of current document to firstName
end tell


or let the script create a new document with 2 text layers and content.

set firstName to text returned of (display dialog "First Name" default answer "Steve" buttons {"OK"} default button 1)
set lastName to text returned of (display dialog "Last Name" default answer "Jobs" buttons {"OK"} default button 1)
-- Change tell application line below to your version of Photoshop
tell application "Adobe Photoshop CS6"
make new document with properties {name:"Testtextlayers"}
make new art layer at current document with properties {name:"First Name", kind:text layer}
make new art layer at current document with properties {name:"Last Name", kind:text layer}
tell text object of art layer 1 of current document
set {contents, size, stroke color} to {firstName, 30.0, {class:RGB hex color, hex value:"913b8e"}}
end tell
tell text object of art layer 2 of current document
set {contents, size, stroke color, position} to {lastName, 48.0, {class:RGB hex color, hex value:"339966"}, {3, 4}}
end tell
end tell

troyman11
Mar 16, 2013, 08:30 PM
Lots of great information. I'm looking into it and I will let you know the results. Thanks for the push!

troyman11
Mar 18, 2013, 06:39 PM
Well I have it working now. Now instead of asking for a dialog box can i just have a textedit file that it gets from.
Get line one of lastname.txt for example ?
line 1: Last Name
line 2: First Name

set firstName to text returned of (display dialog "First Name" default answer "Bill" buttons {"OK"} default button 1)
set lastName to text returned of (display dialog "Last Name" default answer "Gates" buttons {"OK"} default button 1)

troyman11
Mar 18, 2013, 07:40 PM
Hello,
Is it possible to get a line from text edit and then set it as a variable in applescript.

For example:
Textedit
Line One: Ran
Line Two: Man
applescript
get contents of line one
get contents of line two
Set contents of line one as VERB
Set contents of line two as NOUN

chown33
Mar 18, 2013, 07:52 PM
Google search terms:
applescript read file

Many of the search results will be tutorials, examples, or sample code. You can narrow the search results by adding the appropriate keyword to the search terms: tutorial, example, or sample.


The AppleScript commands at the heart of file read/write can be found in the scripting dictionary of StandardAdditions.

1. Run AppleScript Editor.app.
2. Choose "Open Dictionary..." from the File menu.
3. Scroll down to "ScriptingAdditions.osax". **
4. Open it.
5. Look under the "File Read/Write" heading.


** You may or may not see the ".osax" suffix. I always run with all extensions visible.

kryten2
Mar 18, 2013, 08:03 PM
More than one way of doing this but you can try something like this :

-- Opens a choose file dialog to select your text file to read
set theNames to (read (choose file) as «class utf8»)
set lastName to first paragraph of theNames
set firstName to second paragraph of theNames

troyman11
Mar 18, 2013, 08:07 PM
More than one way of doing this but you can try something like this :

-- Opens a choose file dialog to select your text file to read
set theNames to (read (choose file) as «class utf8»)
set lastName to first paragraph of theNames
set firstName to second paragraph of theNames


Getting this error?
for now im just
display dialog lastname

kryten2
Mar 18, 2013, 08:21 PM
A plain text file not a Rich Text File. Notice the \rtf.

troyman11
Mar 18, 2013, 08:21 PM
figured it out as i was saving as a nonreadable utf file. shift command t then save as .txt did it for me. Thank You so much for all your help.