Past items through photoshop based on folder name.

This is a continuation of this topic http://macscripter.net/viewtopic.php?id=38276Get list of folders on desktop and then make folders based on name.

The script for creating the folders is working fine, I am now trying to pass the files of the folder through photoshop.
This part of the script runs out the error, can’t get every file of…

How should this look to work and after the if how do a construct another if and else? so that if the brand doesn’t equal Diva but equals Freedom then do…
I need to put lots of these ifs in but not sure how the rest should go

Thanks

Matt

property type_list : {"PHOTOSHOP"}
property extension_list : {"psd"}

--Setup list of folders and process details of folders

set dtF to paragraphs of (do shell script "ls -F ~/Desktop | grep '/' | cut -d'/' -f1")
repeat with i from 1 to number of items in dtF
	set this_item to item i of dtF
	if this_item does not start with "2_" and this_item does not start with "Hot" then
		try
			set folderPath to this_item
			set {oldTID, my text item delimiters} to {my text item delimiters, ":"}
			set folderName to last text item of folderPath
			set my text item delimiters to "_WK"
			set FolderEndName to last text item of folderName
			set brandName to first text item of folderName
			set my text item delimiters to "_PSD"
			set weekNumber to first text item of FolderEndName
			set my text item delimiters to oldTID
			set theFolder to ("Hal 9000:Users:matthew:Desktop:" & folderName)
			
		end try
	end if
	
	--set up names to destination folders and create locally based on brand name and week number
	try
		set this_local_folder to "Hal 9000:Users:matthew:Pictures:2011-2012"
		set localWeekFolder to my getFolderPath("WK" & weekNumber, this_local_folder)
		set localBrandFolder to my getFolderPath(brandName, localWeekFolder)
		set localBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
		set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", localBrandFolder)
		
		--set up names to destination folders and create over Netwrok including an already exisiting folder
		
		set this_Network_folder to "DCKGEN:Brands:Zoom:Brand - Zoom:Upload Photos:2012:"
		set networkWeekFolder to my getFolderPath("WK" & weekNumber, this_Network_folder)
		set networkBrandFolder to my getFolderPath(brandName, networkWeekFolder)
		set networkBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", networkBrandFolder)
		
		set website_images to "DCKGEN:Website_Images:"
		
		--set up names to destination folders and create over Netwrok for FTP collection (based on a mounted drive)
		
		set this_ftp_folder to "Impulse:"
		set ftpWeekFolder to my getFolderPath("Week" & weekNumber, this_ftp_folder)
		set ftpBrandFolder to my getFolderPath(brandName, ftpWeekFolder)
		set ftpBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
		set ftpBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", ftpBrandFolder)
	end try
	
	--taking the folder identify which process it must follow.
	
	if brandName is equal to "Diva" then set filelist to (files of theFolder whose ¬
		file type is in the type_list or name extension is in the extension_list)
	repeat with alist in filelist
		tell application "Finder"
			set thefile to aFiles as alias
		end tell
		tell application "Adobe Photoshop CS5.1"
			activate
			set myOptions to {class:JPEG save options, quality:12}
			tell front document
				delete layer "Original Image"
				flatten
				resize image resolution 300 resample method none
				
				--sharpen image
				
				filter current layer using unsharp mask with options ¬
					{amount:80, radius:3.2, threshold:0}
				
				
				save in file ((localBrandFolder_High_Res as string) & name) as JPEG with options myOptions without copying
				
				
				--is there a quicker way of saving down the files at this point? Through photoshop or coping the file with terminal?
				--also save to here networkBrandFolder_High_Res
				--ftpBrandFolder_High_Res
				
				--Prepare for Low RES by resetting image history
				
				tell application "Adobe Photoshop CS5.1"
					set current history state of current document to history state 3 ¬
						of current document
				end tell
				
				resize image width 1020
				resize image resolution 300 resample method none
				filter current layer using unsharp mask with options ¬
					{amount:80, radius:3.2, threshold:0}
				
				--add save to lowResFolder with same options	
				save in file ((localBrandFolder_Low_Res as string) & name) as JPEG with options myOptions without copying
				--Also save to here
				--ftpBrandFolder_Low_Res
				--website_images
				--networkBrandFolder_Low_Res
				--close file
				close
				
				
				
			end tell
		end tell
	end repeat
	
	
	
	
end repeat

on getFolderPath(tName, folderPath)
	tell application "Finder" to tell folder folderPath
		if not (exists folder tName) then
			return (make new folder at it with properties {name:tName}) as string
		else
			return (folder tName) as string
		end if
	end tell
end getFolderPath

have you tried coercing the variable to an alias?


if brandName is equal to "Diva" then set filelist to (files of alias theFolder whose ¬
       file type is in the type_list or name extension is in the extension_list)

How can i open the files in the folder if you scroll to “–open file items of the name folder” you can see where I am struggling to run the script.

How should this look to run, currently the script runs, with no errors or anything appearing in the folders.

property type_list : {"PHOTOSHOP"}
property extension_list : {"psd"}

--Setup list of folders and process details of folders

set dtF to paragraphs of (do shell script "ls -F ~/Desktop | grep '/' | cut -d'/' -f1")
repeat with i from 1 to number of items in dtF
	set this_item to item i of dtF
	if this_item does not start with "2_" and this_item does not start with "Hot" and this_item does not start with "Press" then
		try
			set folderPath to this_item
			set {oldTID, my text item delimiters} to {my text item delimiters, ":"}
			set folderName to last text item of folderPath
			set my text item delimiters to "_WK"
			set FolderEndName to last text item of folderName
			set brandName to first text item of folderName
			set my text item delimiters to "_PSD"
			set weekNumber to first text item of FolderEndName
			set my text item delimiters to oldTID
			set theFolder to ("Hal 9000:Users:matthew:Desktop:" & folderName)
			
		end try
	end if
	
	--set up names to destination folders and create locally based on brand name and week number
	try
		set this_local_folder to "Hal 9000:Users:matthew:Pictures:2011-2012"
		set localWeekFolder to my getFolderPath("WK" & weekNumber, this_local_folder)
		set localBrandFolder to my getFolderPath(brandName, localWeekFolder)
		set localBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", localBrandFolder)
		set localBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", localBrandFolder)
		
		--set up names to destination folders and create over Netwrok including an already exisiting folder
		
		set this_Network_folder to "DCKGEN:Brands:Zoom:Brand - Zoom:Upload Photos:2012:"
		set networkWeekFolder to my getFolderPath("WK" & weekNumber, this_Network_folder)
		set networkBrandFolder to my getFolderPath(brandName, networkWeekFolder)
		set networkBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", networkBrandFolder)
		
		set website_images to "DCKGEN:Website_Images:"
		
		--set up names to destination folders and create over Netwrok for FTP collection (based on a mounted drive)
		
		set this_ftp_folder to "Impulse:"
		set ftpWeekFolder to my getFolderPath("Week" & weekNumber, this_ftp_folder)
		set ftpBrandFolder to my getFolderPath(brandName, ftpWeekFolder)
		set ftpBrandFolder_Low_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_LR", ftpBrandFolder)
		set ftpBrandFolder_High_Res to my getFolderPath(brandName & "_WK" & weekNumber & "_HR", ftpBrandFolder)
		
		
		--taking the folder identify which process it must follow.
		
		--open file items in the folders
		
		if brandName is equal to "Diva" then set filelist to (files of alias theFolder whose ¬
			file type is in the type_list or name extension is in the extension_list)
		
		
		repeat with alist in filelist
			tell application "Finder"
				set thefile to aFiles as alias
			end tell
			tell application "Adobe Photoshop CS5.1"
				activate
				
				set myOptions to {class:JPEG save options, quality:12}
				tell front document
					
					--If the quick mask mode has been left on then delete the channel Quick Mask
					
					if (quick mask mode) then delete channel ¬
						"Quick Mask"
					
					delete layer "Original Image"
					flatten
					resize image resolution 300 resample method none
					
					--sharpen image
					
					filter current layer using unsharp mask with options ¬
						{amount:80, radius:3.2, threshold:0}
					
					
					save in file ((localBrandFolder_High_Res as string) & name) as JPEG with options myOptions without copying
					tell application "Finder"
						duplicate last file of localBrandFolder_High_Res to ftpBrandFolder_High_Res with replacing
					end tell
					
					--Prepare for Low RES by resetting image history
					
					tell application "Adobe Photoshop CS5.1"
						set current history state of current document to history state 3 ¬
							of current document
					end tell
					
					resize image width 1020
					resize image resolution 300 resample method none
					filter current layer using unsharp mask with options ¬
						{amount:80, radius:3.2, threshold:0}
					
					--add save to lowResFolder with same options	
					save in file ((localBrandFolder_Low_Res as string) & name) as JPEG with options myOptions without copying
					tell application "Finder"
						duplicate last file of localBrandFolder_Low_Res to website_images with replacing
						duplicate last file of localBrandFolder_Low_Res to ftpBrandFolder_Low_Res with replacing
						duplicate last file of localBrandFolder_Low_Res to networkBrandFolder_Low_Res with replacing
					end tell
					
					--close file
					close
					
					
					
				end tell
				
			end tell
			
		end repeat
	end try
	
	
	
	
end repeat

on getFolderPath(tName, folderPath)
	tell application "Finder" to tell folder folderPath
		if not (exists folder tName) then
			return (make new folder at it with properties {name:tName}) as string
		else
			return (folder tName) as string
		end if
	end tell
end getFolderPath

When you get the file list you need to use a shell script or address the Finder, which you are missing from that line of code. Note how I am coercing the finders file list to an alias list, this is important because the finders standard list of objects (files) won’t work outside of the finder tell blocks. I also noticed that your type_list had the wrong reference (at least based off my version of photoshop) for the file type.


property type_list : {"8BPS"}
property extension_list : {"psd"}

set theFolder to path to desktop
tell application "Finder" to set FileList to (every file of theFolder whose (file type is in type_list) or (name extension is in extension_list)) as alias list

I altered the following

	if brandName is equal to "Diva" then tell application "Finder" to setFileList to (every file of theFolder whose (file type is in type_list) or (name extension is in extension_list)) as alias list

is the following getting the right instructions to open each file and to repeat?

if brandName is equal to "Diva" then tell application "Finder" to setFileList to (every file of theFolder whose (file type is in type_list) or (name extension is in extension_list)) as alias list
		
		
		repeat with alist in setFileList
			tell application "Finder"
				set thefile to aFiles as alias
			end tell
			tell application "Adobe Photoshop CS5.1"
				activate
				open the file thefile