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,

Right now I have this code for taking a files contents and putting it into photoshop. Im trying to expand on this.
I want applescript to let me either choose the file I want it to use or even better just take a list of these files. Input them into Photoshop and Save As "###.psd".

Example:
Folder 1 contains txt files John.txt and Jack.txt.
use first file
use its contents in photoshop
save as john.psd
use second file... repeat
save as jack.psd

My mind is all over the place with this one so anything will help.

Code:
set theNames to ("/Users/myname/Desktop/TEST.txt" as «class utf8»)
set lastName to second paragraph of theNames

tell application "Adobe Photoshop CS5"
	get properties of art layer 3 of current document
	set kind of art layer 3 of current document to text layer
	get properties of text object of art layer 3 of current document
	get contents of text object of art layer 3 of current document
	set contents of text object of art layer 3 of current document to lastName
end tell
 
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
You've given the answers to your questions yourself. A list of files and repeat. You'll have to use a loop. Can you attach an example of John.txt and Jack.txt to your post?
 

troyman11

macrumors newbie
Original poster
Feb 18, 2008
24
0
Dunno the commands

I don't exactly know those commands. such as saving and looping. I uploaded a .txt. The format is extremely basic. I just want to automate this process as much as I can. You helped me last time so hopefully I get your expertise again.
 

Attachments

  • John.txt
    17 bytes · Views: 131
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
I don't exactly know those commands. such as saving and looping. I uploaded a .txt. The format is extremely basic. I just want to automate this process as much as I can. You helped me last time so hopefully I get your expertise again.

In the example I'm using ASObjC Runner to get the part of the filename without the extension. See info link on how to get/use/install it.

An example :

Code:
set theFolder to choose folder with prompt "Choose folder with text files."

tell application "Finder" to set theItems to items of theFolder as alias list

repeat with anItem in theItems
	set anItem to contents of anItem
	set theNames to (read anItem as «class utf8»)
	set firstName to first paragraph of theNames
	set lastName to second paragraph of theNames
	tell application "ASObjC Runner"
		set theFileName to name stub of (about file anItem include only {"name stub"})
	end tell
	createTextLayersPS(theFileName, theFolder, firstName, lastName)
end repeat

on createTextLayersPS(psFileName, psFolderName, psFirstName, psLastName)
	-- Change tell application line below to your version of Photoshop
	tell application "Adobe Photoshop CS6"
		make new document with properties {name:psFileName}
		--create a variable named theDocRef --assign the current (active) document to it 
		set theDocRef to the current document
		--create a variable for the text layer, create the layer as an art layer object 
		--and use the kind property of the art layer object to make it a text layer
		set theFirstTextLayer to make new art layer in theDocRef with properties ¬
			{name:"First Name", kind:text layer}
		set theSecondondTextLayer to make new art layer in theDocRef with properties ¬
			{name:"Last Name", kind:text layer}
		set properties of text object of theFirstTextLayer whose name is "First Name" to {contents:psFirstName, size:30.0, stroke color:{class:RGB hex color, hex value:"913b8e"}}
		set properties of text object of theSecondondTextLayer whose name is "Last Name" to {contents:psLastName, size:48.0, stroke color:{class:RGB hex color, hex value:"339966"}, position:{3, 4}}
		set thesavedoc to save theDocRef in file ((psFolderName as text) & psFileName) as Photoshop format appending lowercase extension
		close thesavedoc
	end tell
end createTextLayersPS

Info : http://www.macosxautomation.com/applescript/apps/runner.html
 

Attachments

  • Screen shot 2013-04-09 at 00.23.36.png
    Screen shot 2013-04-09 at 00.23.36.png
    113 KB · Views: 232
  • Screen shot 2013-04-09 at 00.24.08.png
    Screen shot 2013-04-09 at 00.24.08.png
    24.6 KB · Views: 152
Last edited:

troyman11

macrumors newbie
Original poster
Feb 18, 2008
24
0
Error

Code:
error "Can’t make some data into the expected type." number -1700

Keep getting this error at set theNames to (read anItem as «class utf8»)
 
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Attach your txt files. They need to be plain text files with Unix LF linefeeds and UTF8 encoding. I've used your John.txt file in the example. Does the script error with only John.txt in the folder? Are you using the script or did you make changes to it? If so post the code. Provide as much information as you can with your reply. You have the opportunity to attach files to your replies. Please make use of it.
 

troyman11

macrumors newbie
Original poster
Feb 18, 2008
24
0
Code I am working with

Code:
set theFolder to choose folder with prompt "Choose folder with text files."

tell application "Finder" to set theItems to items of theFolder as alias list

repeat with anItem in theItems
	set anItem to contents of anItem
	set theNames to (read anItem as «class utf8»)
	set firstName to first paragraph of theNames
	set lastName to second paragraph of theNames
	set IDNUMBER to 3rd paragraph of theNames
	set MEMBERSHIP to 4th paragraph of theNames
	tell application "ASObjC Runner"
		set theFileName to name stub of (about file anItem include only {"name stub"})
	end tell
	createTextLayersPS(theFileName, theFolder, firstName, lastName)
end repeat

on createTextLayersPS(psFileName, psFolderName, psFirstName, psLastName)
	-- Change tell application line below to your version of Photoshop
	tell application "Adobe Photoshop CS5"
		open document "/Users/vixtrasolution/Desktop/Testfolder/TEST.psd"
		
		get properties of art layer 1 of current document
		set kind of art layer 1 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
		set contents of text object of art layer 1 of current document to firstName
		--
		get properties of art layer 2 of current document
		set kind of art layer 2 of current document to text layer
		get properties of text object of art layer 2 of current document
		get contents of text object of art layer 2 of current document
		set contents of text object of art layer 2 of current document to lastName
		--
		get properties of art layer 3 of current document
		set kind of art layer 3 of current document to text layer
		get properties of text object of art layer 3 of current document
		get contents of text object of art layer 3 of current document
		set contents of text object of art layer 3 of current document to IDNUMBER
		--
		get properties of art layer 4 of current document
		set kind of art layer 4 of current document to text layer
		get properties of text object of art layer 4 of current document
		get contents of text object of art layer 4 of current document
		set contents of text object of art layer 4 of current document to MEMBERSHIP
		
		save current document in file (((psFolderName as text) & psFileName) & ".psd") as Photoshop format
	end tell
end createTextLayersPS
 

Attachments

  • Testfolder 2.zip
    30 KB · Views: 85

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
The example script given will work for the example you gave in your first post eg n txt files --> creation of n psd files with the names of the txt files.
This is what happens :
The repeat block loop through the txt files. It gets the first and second paragraph from the txt file, the name of the txt file without the extension to be used to save the psd file in the handler, calls the handler with parameters.
Adding things to a script without really knowing what they do will always fail.
This line :

Code:
set theFolder to choose folder with prompt "Choose folder with text files."

couldn't be more clearer than that. Select a folder with txt files. Your testfolder also contains a TEST.psd file. That's why you get the error "Can’t make some data into the expected type." number -1700 when you try to read this file. This can be solved by changing this line :

Code:
tell application "Finder" to set theItems to items of theFolder as alias list

into this :

Code:
tell application "Finder" to set theItems to (items of theFolder whose name extension is "txt") as alias list

The handler :

You added this in the repeat loop :

Code:
	set IDNUMBER to 3rd paragraph of theNames
	set MEMBERSHIP to 4th paragraph of theNames

but the handler doesn't use them eg :

Code:
	createTextLayersPS(theFileName, theFolder, firstName, lastName)

should be something like this :

Code:
	createTextLayersPS(theFileName, theFolder, firstName, lastName, IDNUMBER, MEMBERSHIP)

and to reflect the changes this :

Code:
on createTextLayersPS(psFileName, psFolderName, psFirstName, psLastName)

should be something like this :

Code:
on createTextLayersPS(psFileName, psFolderName, psFirstName, psLastName,psIdNumber,psMemberShip)

Inside the handler you use the parameters of the handler eg :

Code:
set contents of text object of art layer 1 of current document to psFirstName
set contents of text object of art layer 2 of current document to psLastName
set contents of text object of art layer 3 of current document to psIdNumber
set contents of text object of art layer 4 of current document to psMemberShip

Also this line will not work :

Code:
open document "/Users/vixtrasolution/Desktop/Testfolder/TEST.psd"

and this line :

Code:
save current document in file (((psFolderName as text) & psFileName) & ".psd") as Photoshop format

will not save your TEST.psd file.
 
Last edited:

troyman11

macrumors newbie
Original poster
Feb 18, 2008
24
0
U r the man

You are the man. I was able to fix the errors and now it is running perfectly.
I do have one more question. As u can see this is for a membership ID card. On the back I would like to put a barcode on it.

Instead of me manually resizing the image I would like to know if this is possible.
Place a .TIFF image from a folder.
Resize to be the exact specifications of the template barcode.
Put it over the barcode template. (same coordinates?)
Save as a .jpeg
Repeat

I dunno if its different for text files and images. If this is not possible, its completely fine because you already helped me so much.

Thanks,
Troy

attached is properties, back.psd and .tiff example
 

Attachments

  • Screen Shot 2013-04-09 at 5.45.21 PM.png
    Screen Shot 2013-04-09 at 5.45.21 PM.png
    11.1 KB · Views: 142
  • BackExample.zip
    52.3 KB · Views: 77

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
You are the man. I was able to fix the errors and now it is running perfectly.
I do have one more question. As u can see this is for a membership ID card. On the back I would like to put a barcode on it.

Instead of me manually resizing the image I would like to know if this is possible.
Place a .TIFF image from a folder.
Resize to be the exact specifications of the template barcode.
Put it over the barcode template. (same coordinates?)
Save as a .jpeg
Repeat

I dunno if its different for text files and images. If this is not possible, its completely fine because you already helped me so much.

Thanks,
Troy

attached is properties, back.psd and .tiff example

Perhaps not exactly what you wanted but you can give it at try.

Code:
-- Change tell application line below to your version of Photoshop
tell application "Adobe Photoshop CS6"
	activate
	-- Change paths to location of your documents
	set myFilePath to alias POSIX file "/Users/kryten/Documents/TestFolder/BackExample/Example.tif" as text
	set myTemplateFilePath to alias POSIX file "/Users/kryten/Documents/TestFolder/BackExample/BACK.psd" as text
	open alias myTemplateFilePath
	open alias myFilePath
	set theDocRef to document "Example.tif"
	set theTemplateDocRef to document "BACK.psd"
	resize image theDocRef width 1844 height 306 resolution 300 resample method bicubic
	select all theDocRef
	copy
	set current document to theTemplateDocRef
	select theTemplateDocRef region {{110, 40}, {110, 346}, {1954, 346}, {1954, 40}}
	paste with clipping to selection
	merge art layer 1 of current document
	save theTemplateDocRef in file ((alias POSIX file "/Users/kryten/Documents/TestFolder/BackExample/" as text) & "Back") as JPEG appending lowercase extension with copying
	close theDocRef saving no
	close theTemplateDocRef saving no
	--quit
end tell
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.