Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

troyman11

macrumors newbie
Original poster
Feb 18, 2008
24
0
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.
Code:
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
 
Last edited:

sero

macrumors member
Aug 28, 2008
91
14
not really sure what you're trying to do but you could probably get it done using imagemagick.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
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.
Code:
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.

Code:
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.

Code:
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
 

Attachments

  • Screen shot 2013-03-16 at 20.53.33.png
    Screen shot 2013-03-16 at 20.53.33.png
    106.1 KB · Views: 271
  • Screen shot 2013-03-16 at 20.54.11.png
    Screen shot 2013-03-16 at 20.54.11.png
    105.8 KB · Views: 245
  • Screen shot 2013-03-16 at 20.58.17.png
    Screen shot 2013-03-16 at 20.58.17.png
    140.9 KB · Views: 377
  • Screen shot 2013-03-16 at 21.09.44.png
    Screen shot 2013-03-16 at 21.09.44.png
    179.5 KB · Views: 382
Last edited:

troyman11

macrumors newbie
Original poster
Feb 18, 2008
24
0
Lots of great information. I'm looking into it and I will let you know the results. Thanks for the push!
 

troyman11

macrumors newbie
Original poster
Feb 18, 2008
24
0
Worked Perfectly

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
Code:
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

macrumors newbie
Original poster
Feb 18, 2008
24
0
get line from textedit. set as variable

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
 
Last edited:

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
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

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
More than one way of doing this but you can try something like this :

Code:
-- 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

macrumors newbie
Original poster
Feb 18, 2008
24
0
error

More than one way of doing this but you can try something like this :

Code:
-- 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
 

Attachments

  • Screen Shot 2013-03-18 at 9.06.01 PM.png
    Screen Shot 2013-03-18 at 9.06.01 PM.png
    25.1 KB · Views: 254

troyman11

macrumors newbie
Original poster
Feb 18, 2008
24
0
Thanks

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.