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 Jun 2, 2012, 06:07 AM   #1
nazkav
macrumors newbie
 
Join Date: Jun 2012
AppleScripting Photoshop

Hello,
Basically I am trying to write a script that will work in conjunction with photoshop for work. The purpose of the script is
to open up multiple files in photoshop off of a server using an applescript droplet. The files will all have different names and be in different locations
on said server. Photoshop must then crop the files to three different pixel sizes and save them back on the server in specified folders, then Photoshop must covert original opened files to CMYK and save a jpeg and a tiff in another folder on the server. Also the files will be named "filename_rgb.jpg" and I want the CMYK files to be named "filename_cmyk.jpg" and "filename_cmyk.tif" here is my code so far:
Code:
on open myFiles
	tell application "Adobe Photoshop CS4"
		activate
		set myFiles to alias "Macintosh HD:Users:tomfinnane:Desktop:structure:2000x2000:Kav.jpg"
		open myFiles as JPEG
		set ruler units of settings to pixel units
		set theDocument to current document
		tell theDocument
			resize image width 468 height 468 resolution 300 resample method bicubic
		end tell
		save theDocument in file "Macintosh HD:Users:tomfinnane:Desktop:structure:492x492" as JPEG with options {class:JPEG save options, embed color profile:false, quality:12}
		close theDocument
		set myFiles to alias "Macintosh HD:Users:tomfinnane:Desktop:structure:2000x2000:Kav.jpg"
		open myFiles as JPEG
		set ruler units of settings to pixel units
		set theDocument to current document
		tell theDocument
			resize image width 200 height 200 resolution 300 resample method bicubic
		end tell
		save theDocument in file "Macintosh HD:Users:tomfinnane:Desktop:structure:200x200" as JPEG with options {class:JPEG save options, embed color profile:false, quality:12}
		close theDocument
		set myFiles to alias "Macintosh HD:Users:tomfinnane:Desktop:structure:2000x2000:Kav.jpg"
		open myFiles as JPEG
		set ruler units of settings to pixel units
		set theDocument to current document
		tell theDocument
			resize image width 95 height 95 resolution 300 resample method bicubic
		end tell
		save theDocument in file "Macintosh HD:Users:tomfinnane:Desktop:structure:95x95" as JPEG with options {class:JPEG save options, embed color profile:false, quality:12}
		close theDocument
		set myFiles to alias "Macintosh HD:Users:tomfinnane:Desktop:structure:2000x2000:Kav.jpg"
		open myFiles as JPEG
		tell theDocument
			convert to profile "Working CMYK" intent relative colorimetric with blackpoint compensation and dithering
		end tell
		save theDocument in file "Macintosh HD:Users:tomfinnane:Desktop:structure:CMYK" as JPEG with options {class:JPEG save options, embed color profile:false, quality:12}
		close theDocument
		set myFiles to alias "Macintosh HD:Users:tomfinnane:Desktop:structure:2000x2000:Kav.jpg"
		open myFiles as JPEG
		tell theDocument
			convert to profile "Working CMYK" intent relative colorimetric with blackpoint compensation and dithering
		end tell
		set theName to name of current document
		save theDocument in file "Macintosh HD:Users:tomfinnane:Desktop:structure:CMYK" as TIFF with options {class:TIFF save options, embed color profile:false}
	end tell
end open
I have managed to get photoshop to open the files and perform the actions required but when I try to save the last tiff I get an error "file/folder expected" also I can't get the naming portion correct. Also I foresee problems opening multiple files off of a different location. I have set this script up to work on my laptop at home but it must be portable and work from multiple Mac's all connected to the same file server. I am a Creative Photoshop retoucher with an interest in scripting and programming that is why this problem has landed at my door. I am sorry for the length of this question and the fact that the script is so far from complete but I have no prior knowledge of Applescript and accepted this challenge as my boss asked me personally.

I hope there's someone out there who can help

Thanks

nazkav
nazkav is offline   0 Reply With Quote
Old Jun 3, 2012, 01:46 AM   #2
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
I have to admit this one took a little while as I've never scripted Photoshop before. Also had to change a few things from your example especially the saving bits. The naming you would like wasn't exactly clear. Here's a working droplet script tested on Leopard with Photoshop CS2. Dropped files are resized 3 times and 2 cmyk files are created from the original file. The original file is left untouched. Replace CS2 with CS4 and change the paths. Unfortunately I'm on a standalone Mac so couldn't test the server side of your problem. If you want help with that you should post some more information eg what folders are shared on the server(What do you see in Finder-->Shared), a location of a file on the server, an example of a location where you want to put the resized files. Like : Shared Folder on server--> Folder structure --> the resized files go inside the structure folder. Screenshots would make things a lot easier.

Code:
-- This droplet processes files dropped onto the applet 
on open these_items
	repeat with i from 1 to the count of these_items
		set this_item to item i of these_items
		set this_item_string to this_item as string
		set the_item_name to do shell script "sed -E 's|:$||;s|.*:||;s|\\.[^.]*$||' <<< " & quoted form of this_item_string
		my resize_image(this_item, 468, 468, 300, "LeopardFirewire:Users:test:Desktop:" & the_item_name & "_rgb_492x492.jpg")
		my resize_image(this_item, 200, 200, 300, "LeopardFirewire:Users:test:Desktop:" & the_item_name & "_rgb_200x200.jpg")
		my resize_image(this_item, 95, 95, 300, "LeopardFirewire:Users:test:Desktop:" & the_item_name & "_rgb_95x95.jpg")
		my CMYK_image_jpg(this_item, "LeopardFirewire:Users:test:Desktop:" & the_item_name & "_cmyk.jpg")
		my CMYK_image_tif(this_item, "LeopardFirewire:Users:test:Desktop:" & the_item_name & "_cmyk.tif")
	end repeat
end open

on resize_image(the_file, thewidth, theheight, theresolution, thefilename)
	tell application "Adobe Photoshop CS2"
		activate
		open the_file as JPEG
		set ruler units of settings to pixel units
		set theDocument to current document
		tell theDocument
			resize image width thewidth height theheight resolution theresolution resample method bicubic
		end tell
		set thesavedoc to save theDocument in file thefilename as JPEG with options {class:JPEG save options, embed color profile:false, quality:12}
		close thesavedoc
	end tell
end resize_image

on CMYK_image_jpg(the_file, thefilename)
	tell application "Adobe Photoshop CS2"
		activate
		open the_file as JPEG
		set theDocument to current document
		tell theDocument
			convert to profile "Working CMYK" intent relative colorimetric with blackpoint compensation and dithering
		end tell
		set thesavedoc to save theDocument in file thefilename as JPEG with options {class:JPEG save options, embed color profile:false, quality:12}
		close thesavedoc
	end tell
end CMYK_image_jpg

on CMYK_image_tif(the_file, thefilename)
	tell application "Adobe Photoshop CS2"
		activate
		open the_file as JPEG
		set theDocument to current document
		tell theDocument
			convert to profile "Working CMYK" intent relative colorimetric with blackpoint compensation and dithering
		end tell
		set thesavedoc to save theDocument in file thefilename as TIFF with options {class:TIFF save options, embed color profile:false}
		close thesavedoc
	end tell
end CMYK_image_tif
Tip :

Code:
--(path to desktop as text) is the same as "Macintosh HD:Users:tomfinnane:Desktop:"
-- so this also works for constructing paths
set the_desktop_path to (path to desktop as text)
my CMYK_image_tif(this_item, the_desktop_path & the_item_name & "_cmyk.tif")
Attached Thumbnails
Click image for larger version

Name:	Picture 1.png
Views:	9
Size:	26.2 KB
ID:	341671  
Attached Files
File Type: zip Archive.zip (1.21 MB, 11 views)

Last edited by kryten2; Jun 3, 2012 at 08:23 AM.
kryten2 is offline   0 Reply With Quote
Old Jun 3, 2012, 05:39 PM   #3
nazkav
Thread Starter
macrumors newbie
 
Join Date: Jun 2012
Applescript Photoshop

Thank you for your in depth help with my problem.
I've been trying your script all day but unfortunately I keep getting an error when I drop the files on to the droplet

The error is this:

Can't get alias "Macintosh HD:Users:tomfinnaneesktop:Kav_1.jpg

This is probably easily fixed but my Applescript knowledge doesn't extend that far. Any more help would be appreciated. By the way I'm trying to open 3 JPEG'S from my Desktop.

Thanks


nazkav
nazkav is offline   0 Reply With Quote
Old Jun 3, 2012, 07:28 PM   #4
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Strange shouldn't happen as the script worked for me. To debug this I'll need a couple of things.

1) Post the script you're using with the changes you've made(put it between the code tags!)
2) I'll attach another script for you to open in Script Editor and run after you made the necessary changes eg CS4 and paths. It's the same as the droplet with the exception that you have to choose a file manually. It will only process one file and you can comment out the second and third resize handlers and the cmyk handlers eg leave the first my resize_image as it is and put -- before the following four my statements. This will also speed things up. When the script errors it should highlight a section of the script where the error occured. Post a screenshot of the script window. Run the script again this time with the event log pane selected and post a screenshot of the event log. Or select all the text in the event log pane, put it in a text file and post that as attachment.
Attached Thumbnails
Click image for larger version

Name:	Picture 1.png
Views:	53
Size:	178.9 KB
ID:	341736   Click image for larger version

Name:	Picture 2.png
Views:	36
Size:	233.9 KB
ID:	341737  
Attached Files
File Type: zip Adobe CS2 Resize Start Script.zip (6.0 KB, 17 views)
kryten2 is offline   0 Reply With Quote
Old Jun 4, 2012, 04:32 AM   #5
nazkav
Thread Starter
macrumors newbie
 
Join Date: Jun 2012
Applescript Photoshop

Hello,

I've tried your script and it all works fine so here is the script I'm using:
Code:
on open theseItems
	set theLocation to "Macintosh HD:Users:tomfinnane:Desktop"
	tell application "Finder"
		set archiveFolder to make new folder at theLocation with properties {name:"TEST"}
		set firstJpgFolder to make new folder at archiveFolder with properties {name:"2000x2000"}
		set secondJpgFolder to make new folder at archiveFolder with properties {name:"468x468"}
		set thirdJpgFolder to make new folder at archiveFolder with properties {name:"200x200"}
		set fourthJpgFolder to make new folder at archiveFolder with properties {name:"95x95"}
		set cmykFolder to make new folder at archiveFolder with properties {name:"CMYK"}
	end tell
	repeat with i from 1 to the count of theseItems
		set thisItem to item i of theseItems
		set thisItemString to thisItem as string
		set theItemName to do shell script "sed -E 's|:$||;s|.*:||;s|\\.[^.]*$||' <<< " & quoted form of thisItemString
		my image(thisItem, "Macintosh HD:Users:tomfinnane:Desktop:" & thisItemString & "_rgb.jpg")
		my resize_image(thisItem, 468, 468, 300, "Macintosh HD:Users:tomfinnane:Desktop:" & thisItemString & "_rgb.jpg")
		my resize_image(thisItem, 200, 200, 300, "Macintosh HD:Users:tomfinnane:Desktop:" & thisItemString & "_rgb.jpg")
		my resize_image(thisItem, 95, 95, 300, "Macintosh HD:Users:tomfinnane:Desktop:" & thisItemString & "_rgb.jpg")
		my CMYK_image_jpg(thisItem, "Macintosh HD:Users:tomfinnane:Desktop:" & thisItemString & "_cmyk.jpg")
		my CMYK_image_tif(thisItem, "Macintosh HD:Users:tomfinnane:Desktop:" & thisItemString & "_cmyk.tif")
	end repeat
end open

on image(the_file, theFileName)
	tell application "Adobe Photoshop CS4"
		activate
		open the_file as JPEG
		set theDocument to current document
		set theSaveDoc to save theDocument in file theFileName as JPEG with options {class:JPEG save options, embed color profile:false, quality:12}
		close theSaveDoc
	end tell
end image

on resize_image(the_file, theWidth, theHeight, theResolution, theFileName)
	tell application "Adobe Photoshop CS4"
		activate
		open the_file as JPEG
		set ruler units of settings to pixel units
		set theDocument to current document
		tell theDocument
			resize image width theWidth height theHeight resolution theResolution resample method bicubic
		end tell
		set theSaveDoc to save theDocument in file theFileName as JPEG with options {class:JPEG save options, embed color profile:false, quality:12}
		close theSaveDoc
	end tell
end resize_image

on CMYK_image_jpg(the_file, theFileName)
	tell application "Adobe Photoshop CS4"
		activate
		open the_file as JPEG
		set theDocument to current document
		tell theDocument
			convert to profile "Working CMYK" intent relative colorimetric with blackpoint compensation and dithering
		end tell
		set theSaveDoc to save theDocument in file theFileName as JPEG with options {class:JPEG save options, embed color profile:false, quality:12}
		close theSaveDoc
	end tell
end CMYK_image_jpg

on CMYK_image_tif(the_file, theFileName)
	tell application "Adobe Photoshop CS4"
		activate
		open the_file as JPEG
		set theDocument to current document
		tell theDocument
			convert to profile "Working CMYK" intent relative colorimetric with blackpoint compensation and dithering
		end tell
		set theSaveDoc to save theDocument in file theFileName as TIFF with options {class:TIFF save options, embed color profile:false}
		close theSaveDoc
	end tell
end CMYK_image_tif
Just to explain. The bit at the beginning is there to create a file structure. I obviously haven't changed the save paths as I couldn't open the files in the first place.

Thank you so much again for all your help

nazkav
nazkav is offline   0 Reply With Quote
Old Jun 4, 2012, 04:56 AM   #6
nazkav
Thread Starter
macrumors newbie
 
Join Date: Jun 2012
applescript Photoshop

Sorry just thought of something, I am trying to open multiple files on the droplet. Could that have something to do with it?

Thanks

nazkav
nazkav is offline   0 Reply With Quote
Old Jun 4, 2012, 04:25 PM   #7
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
I've tried your script and it all works fine
So everything is fine now?

Quote:
Could that have something to do with it?
With what?

I foresee problems with your tell Finder block. First time you drop something on the droplet the folders will be created, the second time you drop something it will error saying that the folders already exist. You can solve that by using something like this :


Code:
set theLocation to "Macintosh HD:Users:tomfinnane:Desktop:"
tell application "Finder"
	if not (exists folder "TEST" of folder theLocation) then
		make new folder at theLocation with properties {name:"TEST"}
	end if
	set archiveFolder to "Macintosh HD:Users:tomfinnane:Desktop:TEST:"
	if not (exists folder "2000x2000" of folder archiveFolder) then
		set firstJpgFolder to make new folder at archiveFolder with properties {name:"2000x2000"}
	end if
	if not (exists folder "468x468" of folder archiveFolder) then
		set secondJpgFolder to make new folder at archiveFolder with properties {name:"468x468"}
	end if
	if not (exists folder "200x200" of folder archiveFolder) then
		set thirdJpgFolder to make new folder at archiveFolder with properties {name:"200x200"}
	end if
	if not (exists folder "95x95" of folder archiveFolder) then
		set fourthJpgFolder to make new folder at archiveFolder with properties {name:"95x95"}
	end if
	if not (exists folder "CMYK" of folder archiveFolder) then
		set cmykFolder to make new folder at archiveFolder with properties {name:"CMYK"}
	end if
end tell
But then there's another problem with this as the variables simply won't get set because all conditionals return true on a second drop. I would move them out of the if end if block if I were you like I did with the archiveFolder.

I'll try to post a zipped movie as an attachment of my original script in action.

Last edited by kryten2; Jun 4, 2012 at 09:52 PM.
kryten2 is offline   0 Reply With Quote
Old Jun 4, 2012, 05:15 PM   #8
nazkav
Thread Starter
macrumors newbie
 
Join Date: Jun 2012
Applescript Photoshop

Thank you again for your help I will try your solution and let you know. In answer to your questions, basically I tried your script (the one which prompts you to select a file) and it all worked fine. But I was wondering if the reason the droplet wasn't working was because I was dropping multiple files on to it. If your wondering why I'm using a droplet it is because that was the brief from work, they want a droplet on the desktop that is able to handle multiple files.

Thank you

nazkav
nazkav is offline   0 Reply With Quote
Old Jun 4, 2012, 09:47 PM   #9
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
But I was wondering if the reason the droplet wasn't working was because I was dropping multiple files on to it.
That's what droplets are for. To drop multiple files onto. I had just finished that screenrecording I promised when I saw your reply and decided to take one last closer look at the code you posted and I spotted an error. Don't know if this will fix your problem but it's worth a try. See if you can find it. I'll highlight the relevant parts.

Code:
--My code

set the_item_name to do shell script "sed -E 's|:$||;s|.*:||;s|\\.[^.]*$||' <<< " & quoted form of this_item_string
my resize_image(this_item, 468, 468, 300, "LeopardFirewire:Users:test:Desktop:" & the_item_name & "_rgb_492x492.jpg")

--Your code

set theItemName to do shell script "sed -E 's|:$||;s|.*:||;s|\\.[^.]*$||' <<< " & quoted form of thisItemString
my resize_image(thisItem, 468, 468, 300, "Macintosh HD:Users:tomfinnane:Desktop:" & thisItemString & "_rgb.jpg")
For the ScreenRecording. Save the zip files to a folder(eg Folder Screen on your Desktop)-->unzip them(you'll see out_aa,out_ab, out_ac and out_ad)-->move the zip files out of the folder--> Open Terminal--> cd into the folder with the out_ files ( eg cd Desktop/Screen)-->cat the splitted files back together eg cat out_a[a-d]>ScreenRecording.mov Enjoy the droplet in action. I'll attach the script I used in the Screenrecording. It's adapted for use with Adobe Photoshop CS6 thanks to this stupid bug I encountered. More info about the bug here : http://helpx.adobe.com/photoshop/kb/...rror-file.html. So don't copy this blindingly and expect it to work. Take a look at the link and the adaptations will make sense.
Attached Files
File Type: zip out_aa.zip (1.91 MB, 13 views)
File Type: zip out_ab.zip (1.90 MB, 9 views)
File Type: zip out_ac.zip (1.83 MB, 10 views)
File Type: zip out_ad.zip (486.4 KB, 10 views)
File Type: zip Adobe Photoshop CS6 Resize.zip (34.5 KB, 26 views)

Last edited by kryten2; Jun 4, 2012 at 09:53 PM.
kryten2 is offline   0 Reply With Quote
Old Jun 5, 2012, 06:52 AM   #10
nazkav
Thread Starter
macrumors newbie
 
Join Date: Jun 2012
Applescript Photoshop

Hello again,

I've tried all that you told me to do and after massive headaches it finally works. So I would like to thank you for all your help in this matter you have been brilliant.

Thank you a thousand times

nazkav
nazkav is offline   0 Reply With Quote
Old Jun 5, 2012, 09:27 AM   #11
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
No headaches for me at least not massive ones Just a fun challenge. Thank you for the feedback.
kryten2 is offline   0 Reply With Quote
Old Jan 11, 2013, 12:22 PM   #12
applepie375
macrumors newbie
 
Join Date: Jan 2013
AppleScripting Photoshop

Kryten2,

I found your work on this applescript and wanted to give it a try. It gets me to the point of creating a TEST folder on the desktop with the correct subfolders, however, I get an error message that reads it "Can't get alias" with the path to the User folder and the Desktop with the folder name I am dragging onto the droplet. Any help or ideas that I can attempt would be great. Thanks in advance for any help.

applepie375
applepie375 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
need some Applescripting help badly!!! retselseer Mac Programming 3 Nov 27, 2013 10:11 AM
Applescripting Time Machine laskie OS X Mavericks (10.9) 3 Nov 24, 2013 11:27 AM
Photoshop vs. Photoshop Elements for Novice Photographer guzhogi Digital Photography 13 Nov 16, 2013 06:30 AM
Adobe Offering Photoshop CC and Lightroom for $9.99/Month to Current Photoshop Owners MacRumors Mac Blog Discussion 162 Oct 12, 2013 10:55 PM

Forum Jump

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

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

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