applescript with Photshop text layers

Discussion in 'Mac Programming' started by troyman11, Mar 15, 2013.

  1. troyman11, Mar 15, 2013
    Last edited: Mar 15, 2013

    macrumors newbie

    Joined:
    Feb 18, 2008
    #1
    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
     
  2. macrumors member

    Joined:
    Aug 28, 2008
    #2
    not really sure what you're trying to do but you could probably get it done using imagemagick.
     
  3. kryten2, Mar 16, 2013
    Last edited: Mar 16, 2013

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #3
    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 Files:

  4. thread starter macrumors newbie

    Joined:
    Feb 18, 2008
    #4
    Lots of great information. I'm looking into it and I will let you know the results. Thanks for the push!
     
  5. thread starter macrumors newbie

    Joined:
    Feb 18, 2008
    #5
    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)
    
     
  6. troyman11, Mar 18, 2013
    Last edited: Mar 18, 2013

    thread starter macrumors newbie

    Joined:
    Feb 18, 2008
    #6
    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
     
  7. macrumors 603

    Joined:
    Aug 9, 2009
    #7
    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.
     
  8. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #8
    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
    
     
  9. thread starter macrumors newbie

    Joined:
    Feb 18, 2008
    #9
    error

    Getting this error?
    for now im just
    display dialog lastname
     

    Attached Files:

  10. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #10
    A plain text file not a Rich Text File. Notice the \rtf.
     

    Attached Files:

  11. thread starter macrumors newbie

    Joined:
    Feb 18, 2008
    #11
    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.
     

Share This Page