Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 15, 2013, 04:49 PM   #1
troyman11
macrumors newbie
 
Join Date: Feb 2008
applescript with Photshop text layers

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 by troyman11; Mar 15, 2013 at 04:55 PM.
troyman11 is offline   0 Reply With Quote
Old Mar 15, 2013, 07:22 PM   #2
sero
macrumors member
 
Join Date: Aug 2008
not really sure what you're trying to do but you could probably get it done using imagemagick.
sero is offline   0 Reply With Quote
Old Mar 16, 2013, 04:14 PM   #3
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
Originally Posted by troyman11 View Post
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
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2013-03-16 at 20.53.33.png
Views:	16
Size:	106.1 KB
ID:	402859   Click image for larger version

Name:	Screen shot 2013-03-16 at 20.54.11.png
Views:	22
Size:	105.8 KB
ID:	402860   Click image for larger version

Name:	Screen shot 2013-03-16 at 20.58.17.png
Views:	96
Size:	140.9 KB
ID:	402861  

Click image for larger version

Name:	Screen shot 2013-03-16 at 21.09.44.png
Views:	58
Size:	179.5 KB
ID:	402865  
__________________
Space Corps Directive 34124

Last edited by kryten2; Mar 16, 2013 at 06:46 PM.
kryten2 is offline   0 Reply With Quote
Old Mar 16, 2013, 09:30 PM   #4
troyman11
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
Lots of great information. I'm looking into it and I will let you know the results. Thanks for the push!
troyman11 is offline   0 Reply With Quote
Old Mar 18, 2013, 07:39 PM   #5
troyman11
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
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 is offline   0 Reply With Quote
Old Mar 18, 2013, 08:40 PM   #6
troyman11
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
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 by troyman11; Mar 18, 2013 at 08:41 PM. Reason: Applescript
troyman11 is offline   0 Reply With Quote
Old Mar 18, 2013, 08:52 PM   #7
chown33
macrumors 603
 
Join Date: Aug 2009
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.
chown33 is offline   0 Reply With Quote
Old Mar 18, 2013, 09:03 PM   #8
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Mar 18, 2013, 09:07 PM   #9
troyman11
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
error

Quote:
Originally Posted by kryten2 View Post
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
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-03-18 at 9.06.01 PM.png
Views:	20
Size:	25.1 KB
ID:	403236  
troyman11 is offline   0 Reply With Quote
Old Mar 18, 2013, 09:21 PM   #10
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
A plain text file not a Rich Text File. Notice the \rtf.
Attached Thumbnails
Click image for larger version

Name:	Picture 5.png
Views:	18
Size:	88.0 KB
ID:	403238  
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Mar 18, 2013, 09:21 PM   #11
troyman11
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
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.
troyman11 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Formatting text file in AppleScript dam316 Mac Programming 1 May 5, 2014 11:21 AM
Append Text to Text File in Applescript BobRon Mac Programming 2 Mar 23, 2014 03:52 PM
AppleScript - Selecting specific text in Outlook message sitryd Mac Programming 2 May 30, 2013 12:57 PM
Best spreadsheet/DB for text manipulation, AppleScript macmesser Mac Applications and Mac App Store 2 Dec 2, 2012 11:10 AM
Best Photoshop alternative for iPhone? (compositing/layers, text, custom canvas size) nagromme iPhone and iPod touch Apps 0 Oct 16, 2012 02:15 AM

Forum Jump

All times are GMT -5. The time now is 06:33 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC