Newb seeking help w batch image processing applescript/automator app.

I can’t locate Digital Photo Professional in Canon website. Only updaters. Probably is only available for Cnaon users on CD/DVD.
This app has a dictionary? Try to open it with AppleScript Editor.

Stefano - Ame

Stefano

you have to select your OS and then drop down the software tab. there should be an entry called:

EOS Digital Solution Disk Software 28.2A for Mac OS X

they used to catch a lot f heat for not providing that but seem to have snuck it in without anyone noticing…
http://www.dslrfilmnoob.com/2013/08/30/canon-dpp-eos-utility-disk/

as far as I know there is no dictionary for DPP but I’ll do some digging to see if there is anything I can break into. Appreciate all of your help man, really I do. Lemme know if you come up with anything?

Some SLIGHT improvements. I have UIScripted all of the button presses instead of relying on keystroking and everything seems to be running more smoothly. My new problem is the fact that DPP INSISTS on randomly (not always) opening a new window (of a single image) when I open a new file. That new window keeps the rest of my UIscripting from working. In my code (last posted version) I have the variable “aFile” set up to trigger DPP to open it, thereby switching the folder view to select the new “job” as it were. That seems to be the only way to get DPP to browse to the folder I want since all of the UIScriptable events are generic and can’t really point to specific item names.

ex: I have a folder tree on the left with the ALL JOBS folder and drop downs to JOB1, JOB2 etc. and the UI Inspector is returning generic names for them, OR if I use this handy script I found, (which is awesome for UI scripts) I realize that the folder names change per job and thereby ruin my chances of pointing at them specifically.

Anybody have a way to tell a window “go away” without actually knowing the name of it? “front window” doesn’t always work because it sometimes closes the main window, which I need for the rest of the UIScript.

Oh, Here’s the link to that awesome UI finder thingy:

http://hints.macworld.com/article.php?story=20111208191312748

Stefano,
Oh man, I can’t believe it took me this long to come up with something so simple. Plain as the nose on my face. My solution was to simply close every window of DPP then open a new one. This leaves me in the folder view I want and guarantees there are no windows in the way. So silly! So I have a couple simple questions:

#1: If I need to check and make a new “TIFF” folder inside the “folderPath”, where do I put it? I am using the recursion script you made but want to make sure I’m not endlessly making folders inside folders. Here is the script I made for making the folder and opening the first file in DPP:


on jobFolder(thisFolder)
launch application "Digital Photo Professional"
tell application "Finder"
set aFile to item 1 of folder thisFolder --to force DPP to browse into the folder
set thePath to POSIX path of thisFolder as text
set tifFolder to thePath & "TIFS"
if not (exists folder "TIFS" of folder thisFolder) then
do shell script "/bin/mkdir -p " & quoted form of POSIX path of tifFolder --make new TIF folder to save files in
end if
open aFile using application file "Digital Photo Professional.app" of folder "Digital Photo Professional" of folder "Canon Utilities" of folder "Applications" of startup disk
end tell

#2: What should I use as the variable replacement for the original input? In your recursion script:

property globalFoldersList : missing value

set globalFoldersList to {}
set folderPath to "Macintosh HD:Users:USER:Desktop:RAWS:ALL JOBS:"
recursiveCheck(folderPath)

I need folderPath to be the folder that is dropped on the application.

Hi unklhefe,

I completed the routine adding a TIFF create dir handler that, for each folder found create a directory.
I also apply some changes handling directly the dropped folder (when you drop the result is a list of elements).
The TIFF Dir creation happen at the end. So, dragged folder is get as input for recursive routine.
The recursive routine generate a list of all folders and subsolders found and store them in the finalFoldersList variable.
The createTIFFDir scan the array finalFoldersList and use the “magic” mkdir -p command to create TIFF directory generating TIFF folders only on directory not named “TIFF” (whose path don’t end with “:TIFF:”).

property finalFoldersList : missing value
property numTiffDir : missing value

on open draggedFolderTmp
	set numFolders to count of draggedFolderTmp
	if numFolders > 1 then
		display dialog "Drag one folder at time." buttons {"OK"} default button 1
	else
		set folderPath to (item 1 of draggedFolderTmp) as string
		set finalFoldersList to {}
		set numTiffDir to 0
		recursiveCheck(folderPath)
		createTIFFDir()
		display dialog "Found " & (count (finalFoldersList)) & " folders." & return & "I created " & numTiffDir & " TIFF folders." buttons {"OK"} default button 1
	end if
end open

on recursiveCheck(folderPathToCheck)
	tell application "Finder"
		set foldersList to (name of every folder of item folderPathToCheck)
	end tell
	set numFolder to count foldersList
	repeat with j from 1 to numFolder
		set newFolderPath to (folderPathToCheck & item j of foldersList & ":") as string
		copy newFolderPath to end of finalFoldersList
		recursiveCheck(newFolderPath)
	end repeat
end recursiveCheck

on createTIFFDir()
	repeat with f from 1 to count finalFoldersList
		set folderPath to item f of finalFoldersList
		if folderPath does not end with ":TIFF:" then
			set numTiffDir to numTiffDir + 1
			do shell script "/bin/mkdir -p " & quoted form of (POSIX path of (folderPath & "TIFF:"))
		end if
	end repeat
end createTIFFDir

Stefano - Ame

Browser: Safari 537.75.14
Operating System: Mac OS X (10.8)

OK! So I am attempting to add these two parts together to make one big drag/drop automation that requires NO feedback. We want this to be a process that happens overnight without human input, so I had to take out a few of the dialogs, etc. so it can run non-stop. I am having a hard time keeping all of these variables (and their types) straight so you will have to excuse my ignorance here. @Stefano- I just copied your “make folder” subroutine a couple of times to make JPG and TIF folders as well, but I will be moving those all into one subroutine; I am just trying to get this all happening in the right order and running smoothly first.

The first section of processing the RAW Files from DPP works fine “jobFolder” but I can’t seem to figure out why I can’t recall “finalFoldersList” to start the “process_item” subroutine.If I can get files handed into that subroutine, then all I will need to do to finish this is make a sorting routine at the end to put the RAWS in their folders.

property finalFoldersList : missing value
property numTiffDir : missing value
property numJPEGDir : missing value
property numRAWDir : missing value

on open draggedFolderTmp
	set numFolders to count of draggedFolderTmp
	if numFolders > 1 then
		display dialog "Drag one folder at time." buttons {"OK"} default button 1
	else
		set folderPath to (item 1 of draggedFolderTmp) as string
		set finalFoldersList to {}
		set numTiffDir to 0
		set numJPEGDir to 0
		set numRAWDir to 0
		recursiveCheck(folderPath)
		
		repeat with x from 1 to the count of finalFoldersList
			set thisFolder to (item x of finalFoldersList)
			jobFolder(thisFolder)
		end repeat
		
		repeat with i from 1 to the count of VARIABLE--what kind and where should I get it?
			set this_item to (item i of VARIABLE)
			set the item_info to info for this_item
			if folder of the item_info is true then
				process_folder(this_item)
			else if name extension of the item_info contains {tif, tiff} then
				process_item(this_item)
			end if
		end repeat
		
		createTIFFDir()
		createJPEGDir()
		createRAWDir()
		
		
	end if
	
end open

Everything is sorted except for ONE thing! I can’t seem to get the leftover RAW files into the “RAW” folder that I create. I know it has something to do with either coercing the path into the right form or something equally banal. the section

move (every file of thisFolder whose name extension is "CR2") to rawFolder

errors out with “can’t get every file…etc”

anyone have a second to help me put this nail in the coffin?

on jobFolder(thisFolder)
	launch application "Digital Photo Professional"
	
	tell application "Finder"
		
		set aFile to item 1 of folder thisFolder --to force DPP to browse into the folder
		set allFiles to every file of thisFolder
		set thePath to POSIX path of thisFolder as text
		set rawFolder to POSIX path of (thePath as text) & "RAW"
		display dialog rawFolder
		do shell script "/bin/mkdir -p " & quoted form of (POSIX path of (thePath & "RAW"))
		open aFile using application file "Digital Photo Professional.app" of folder "Digital Photo Professional" of folder "Canon Utilities" of folder "Applications" of startup disk
		
	end tell

Hi unklhefe,

About moving files you have to use correct syntax:

set sourceFolder to "Macintosh HD:Users:adminosx:Desktop:A:"
set destinationFolder to "Macintosh HD:Users:adminosx:Desktop:B:"

tell application "Finder"
	move (every file of folder sourceFolder whose name extension is "CR2") to folder destinationFolder
end tell

You forgot of folder … and to folder

About JobFolder routine:

the variable thePath is already Posix path, so when you execute do shell script you don’t need to coerce again to posix path.

try this:

set thePath to (POSIX path of thisFolder) as string
set rawFolder to (POSIX path of (thisFolder & “RAW”)) as string
do shell script "/bin/mkdir -p " & quoted form of rawFolder

Probably you can remove the line set thePath if not used…

Stefano - Ame

Ahhh, I see. Hmm. Well now I am getting a "Can’t get class <> of “/Users/user/desktop/job/RAW” of application “Finder.” I put the mk-dir shell script and the move command in that first Tell “finder” block just to make sure it would make the folder/move the files correctly, that IS a finder command is it not?

on jobFolder(thisFolder)
	launch application "Digital Photo Professional"
	
	tell application "Finder"
		
		set aFile to item 1 of folder thisFolder --to force DPP to browse into the folder
		set thePath to (POSIX path of thisFolder) as string
		open aFile using application file "Digital Photo Professional.app" of folder "Digital Photo Professional" of folder "Canon Utilities" of folder "Applications" of startup disk
		set rawFolder to (POSIX path of (thisFolder & "RAW")) as string
		do shell script "/bin/mkdir -p " & quoted form of rawFolder
		move (every file of folder thisFolder whose name extension is "CR2") to folder rawFolder
	end tell

Hi,

the Finder does not accept POSIX paths.
For the shell you need always POSIX paths (slash separated)
For the Finder you need always HFS paths (colon separated)


on jobFolder(thisFolder)
	launch application "Digital Photo Professional"
	
	tell application "Finder"
		set aFile to item 1 of folder thisFolder --to force DPP to browse into the folder
		open aFile using application file "Digital Photo Professional.app" of folder "Digital Photo Professional" of folder "Canon Utilities" of folder "Applications" of startup disk
		set rawFolder to thisFolder & "RAW:"
		do shell script "/bin/mkdir -p " & quoted form of POSIX path of rawFolder
		move (every file of folder thisFolder whose name extension is "CR2") to folder rawFolder
	end tell
end jobFolder

In all the reading I have been doing learning this stuff I had forgotten such a simple thing. Thank you. I’m almost finished now!

Completely done now. @Stefano, if you ever get to the states, or if I get back over to Milano, I’m buying you a beer (or 100 beers). For those unwilling to read through the tornado of this thread as I have tripped my way to a working app, here’s the bottom line:

This script takes folders of Canon RAW .CR2 files and batches them out with the last “Batch” setting applied in Canon’s DPP (Digital Photo Professional) software. It then uses Adobe Photoshop to save certain filenames as JPEG and the rest as LZW compressed TIFF as well as sorts each respective filetype into folders inside each original folder.

Big thanks to Stefano (ame), StefanK, Shane Stanley and the countless others in the scripting community for the help. I hope other people get some use out of this! I’m looking forward to sticking around and learning/sharing when I can. What a great community you all are. THANK YOU.

property finalFoldersList : missing value

on open draggedFolderTmp
	set numFolders to count of draggedFolderTmp
	if numFolders > 1 then
		display dialog "You are only allowed to drag ONE folder full of folders." buttons {"Sorry"} default button 1
	else
		set folderPath to (item 1 of draggedFolderTmp) as string
		set finalFoldersList to {}
		recursiveCheck(folderPath)
		
		repeat with x from 1 to the count of finalFoldersList
			set thisFolder to (item x of finalFoldersList)
			set this_folder to thisFolder
			jobFolder(thisFolder)
			process_folder(thisFolder)
		end repeat
	end if
	
end open
-------------------------------------
--Subroutines--

on recursiveCheck(folderPathToCheck)
	tell application "Finder"
		set foldersList to (name of every folder of item folderPathToCheck)
	end tell
	set numFolder to count foldersList
	repeat with j from 1 to numFolder
		set newFolderPath to (folderPathToCheck & item j of foldersList & ":") as string
		copy newFolderPath to end of finalFoldersList
		recursiveCheck(newFolderPath)
	end repeat
end recursiveCheck

------

on process_folder(this_folder)
	set these_items to list folder this_folder without invisibles
	repeat with z from 1 to the count of these_items
		set this_item to alias ((this_folder as text) & (item z of these_items))
		set the item_info to info for this_item
		if (alias of the item_info is false) then
			process_item(this_item)
		end if
	end repeat
end process_folder

------

on jobFolder(thisFolder)
	launch application "Digital Photo Professional"
	
	tell application "Finder"
		
		set aFile to item 1 of folder thisFolder --to force DPP to browse into the folder
		set thePath to (POSIX path of thisFolder) as string
		open aFile using application file "Digital Photo Professional.app" of folder "Digital Photo Professional" of folder "Canon Utilities" of folder "Applications" of startup disk
		set rawFolder to thisFolder & "RAW:"
		do shell script "/bin/mkdir -p " & quoted form of POSIX path of rawFolder
		
	end tell
	
	tell application "Digital Photo Professional"
		activate
	end tell
	
	tell application "System Events" --UI scripted section to control DPP. Selects all files, browses to TIF folder and executes Batch
		
		tell process "Digital Photo Professional"
			delay 1
			tell application "Digital Photo Professional"
				activate
				tell application "System Events" to tell process "Digital Photo Professional"
					click button 1 of window 1
					try
						click button 1 of window 1
						error
					end try
					try
						click button 1 of window 1
						error
					end try
				end tell
			end tell
			keystroke "n" using command down
			perform action "AXPress" of menu item "Select all" of menu "Edit" of menu bar item "Edit" of menu bar 1 of application process "Digital Photo Professional" of application "System Events"
			perform action "AXPress" of menu item "Batch process..." of menu "File" of menu bar item "File" of menu bar 1 of application process "Digital Photo Professional" of application "System Events"
			perform action "AXPress" of button "Browse..." of group "Save folder" of window "Batch settings" of application process "Digital Photo Professional" of application "System Events"
			keystroke thePath
			delay 1
			key code 36
			perform action "AXPress" of button "Open" of window "Open" of application process "Digital Photo Professional" of application "System Events"
			delay 0.5
			perform action "AXPress" of button "Execute" of window "Batch settings" of application process "Digital Photo Professional" of application "System Events"
		end tell
		
	end tell
	-----------
	-- wait until the first job is done before processing the next	--------
	tell application "Digital Photo Professional Batch"
		activate
		tell application "System Events"
			set window_check to false
			repeat until (window_check)
				if (process "Digital Photo Professional Batch" exists) then
					delay 1
				else
					set window_check to true
				end if
			end repeat
		end tell
	end tell
	tell application "Finder"
		move (every file of folder thisFolder whose name extension is "CR2") to folder rawFolder
	end tell
	
end jobFolder

------

on process_item(this_item)
	set the item_info to info for this_item
	set nam to the name of the item_info
	set dir to the POSIX path of (this_item as alias)
	if nam contains "tif" then
		if nam contains "_y" or nam contains "_t" or nam contains "_a" or nam contains "_c" then
			
			tell application "Finder"
				set jpgFolder to POSIX path of ((this_item as text) & "::") & "JPEG"
				do shell script "/bin/mkdir -p " & quoted form of jpgFolder
				tell application "Adobe Photoshop CS6"
					open file (this_item as text) showing dialogs never
					save current document in jpgFolder as JPEG with options {class:JPEG save options, embed color profile:false, format options:optimized, quality:12} appending lowercase extension without copying
					close the current document
				end tell
				delete this_item
			end tell
		else
			tell application "Finder"
				set tifFolder to POSIX path of ((this_item as text) & "::") & "TIFF"
				do shell script "/bin/mkdir -p " & quoted form of tifFolder
				tell application "Adobe Photoshop CS6"
					open file (this_item as text) showing dialogs never
					save current document in tifFolder as TIFF with options {class:TIFF save options, embed color profile:false, image compression:LZW, byte order:IBM PC}
					close the current document
				end tell
				delete this_item
			end tell
		end if
	end if
end process_item

Hi unklhefe,

One more thing…

Looking quickly your script you delete the file at the end.
But all files remain in the trash and in about 24 hours, with RAW files, your disk will be full :wink:
The Delete Finder command just move the file into trash.
As I know the Finder cannot delete the file without empty trash command. But if for any reason you have locked file this generate a dialog.

In all my scripts, when I need to delete a file, usually I use this command and the file is immediately deleted from disk:

set imagePath to "Macintosh HD:Users:adminosx:Desktop:Top Shop _ 25_large_alta.jpg"
do shell script "/bin/rm -f " & quoted form of (POSIX path of imagePath) 

The second point is that you use alias of files.
I use always string. The main difference (Shane and Stefan can confirm this or not) is that with alias file need to exists.
With string, path strings, you can generate references that don’t yet exists. I use this a lot in my apps.
Not using aliases, but working with normal strings, is much more powerful and flexible in my experience.

Stefano - Ame

Stefano - Good to know on the alias thing. That also helps me keep that straight in my head. I tend to confuse many of these things so any type of simplification of, “I will always do this” helps me. On the topic of deleting files, we clear our trash several times a day :slight_smile: For the several hundred images we need to process at the end of each day, we have shot at least 20 versions before we get the finals. We store our RAW files for 30 days in other drives so we can always go back and reprocess in case of image revisions. Emptying trash is always a part of our workflow, but if need to make other edits to the script I will incorporate that shellscript in future versions. Right now we are just really needing to get this up and running so I will leave it as is for the time being. Thanks again for all of your help and say hello to sunny Milano for me!