[AppleScript] Multiple Files thru photoshop. txt->psd. - MacRumors Forums
Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 8, 2013, 02:16 PM   #1
troyman11
macrumors newbie
 
Join Date: Feb 2008
[AppleScript] Multiple Files thru photoshop. txt->psd.

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 by troyman11; Apr 8, 2013 at 02:17 PM. Reason: added end tell
troyman11 is offline   0 Reply With Quote
Old Apr 8, 2013, 03:01 PM   #2
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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?
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Apr 8, 2013, 03:24 PM   #3
troyman11
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
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.
Attached Files
File Type: txt John.txt (17 Bytes, 19 views)

Last edited by troyman11; Apr 8, 2013 at 03:34 PM.
troyman11 is offline   0 Reply With Quote
Old Apr 8, 2013, 05:47 PM   #4
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
Originally Posted by troyman11 View Post
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/appl...ps/runner.html
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2013-04-09 at 00.23.36.png
Views:	15
Size:	113.0 KB
ID:	406951   Click image for larger version

Name:	Screen shot 2013-04-09 at 00.24.08.png
Views:	13
Size:	24.6 KB
ID:	406952  
__________________
Space Corps Directive 34124

Last edited by kryten2; Apr 13, 2013 at 11:22 PM. Reason: Modified code
kryten2 is offline   0 Reply With Quote
Old Apr 8, 2013, 08:28 PM   #5
troyman11
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
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 by troyman11; Apr 8, 2013 at 08:35 PM.
troyman11 is offline   0 Reply With Quote
Old Apr 9, 2013, 08:01 AM   #6
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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.
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Apr 9, 2013, 12:37 PM   #7
troyman11
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
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
Attached Files
File Type: zip Testfolder 2.zip (30.0 KB, 8 views)
troyman11 is offline   0 Reply With Quote
Old Apr 9, 2013, 03:02 PM   #8
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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.
__________________
Space Corps Directive 34124

Last edited by kryten2; Apr 9, 2013 at 03:11 PM.
kryten2 is offline   0 Reply With Quote
Old Apr 9, 2013, 04:49 PM   #9
troyman11
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
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
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2013-04-09 at 5.45.21 PM.png
Views:	13
Size:	11.1 KB
ID:	407100  
Attached Files
File Type: zip BackExample.zip (52.3 KB, 8 views)
troyman11 is offline   0 Reply With Quote
Old Apr 13, 2013, 10:12 PM   #10
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
Originally Posted by troyman11 View Post
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
__________________
Space Corps Directive 34124

Last edited by kryten2; Apr 13, 2013 at 11:43 PM.
kryten2 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
Applescript - formatting a txt file using write dam316 Mac Applications and Mac App Store 0 May 4, 2014 05:26 PM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Programming 0 Oct 28, 2013 11:38 PM
AppleScript: How do I save multiple Excel sheets to one pdf using Applescript sbtaylor1 Mac Applications and Mac App Store 0 Oct 28, 2013 11:32 PM
iDraw 2.3 Public Beta - Photoshop PSD import/export, and more Indeeo Mac Applications and Mac App Store 0 Jul 10, 2013 11:09 AM
Resolved: Applescript: List/txt.file question h1068 Mac Programming 5 Jul 3, 2012 06:30 PM

Forum Jump

All times are GMT -5. The time now is 03:37 AM.

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

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