Image Capture; Automatic Task

Hi guys,

I have a applescript script which I saved as app. I’d like Image Capture to run it right after it downloaded my images. I have a problem that when images are downloaded the script will not start running. When I run the script on it’s own by clicking on it it runs fine.

I think it must be something regarding triggering the script to run, but I don’t seem to be able to figure it out.

Thanks for helping out

Marek


property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct"}
property BasePath : "Macintosh HD:Users:MAF:Pictures:Photography:Originals:"

on run
	
	
	set the fresh_folder to choose folder with prompt "Pick a folder containing the images to process:"
	
	tell application "Finder"
		set file_list to every file of the fresh_folder whose file type is in the type_list or name extension is in the extension_list
	end tell
	
	repeat with i from 1 to number of items in the file_list
		tell application "Finder"
			set this_item to item i of the file_list
			set itemDateCreation to the creation date of this_item
			
			-- Make sure that month and day are in XX format
			if (month of itemDateCreation < 10) then
				set monthNum to "0" & (month of itemDateCreation as integer)
			else
				set monthNum to (month of itemDateCreation as integer)
			end if
			if (day of itemDateCreation < 10) then
				set dayNum to "0" & (day of itemDateCreation as integer)
			else
				set dayNum to (day of itemDateCreation as integer)
			end if
			
			-- setup destination folder
			set newFolderName to ((year of itemDateCreation as integer) & "-" & (monthNum) & "-" & (dayNum)) as string
			set DestFolder to BasePath & newFolderName
			
			-- check whether the destination folder exists
			if not (folder DestFolder exists) then
				make new folder at BasePath with properties {name:newFolderName}
				set w to make Finder window to folder DestFolder
				set p to icon view options of w
				set the icon size of p to 128
			end if
			
			move this_item to DestFolder
			
		end tell
	end repeat
	
	display dialog "There was " & number of items in the file_list & " file(s) processed."
	
end run


Hi Marek,

There are mainly two ways to have a script do something when you add something to a folder. The usual way is with folder actions where you connect your script to the folder and when something is added the script runs. I’ve read that folder actions is not consistant in Tiger. The other way is to monitor a folder every few seconds with an idle handler. Here’s an example where I just included the moving part:


property file_extensions : {"jpg", "pdf", "gif"}
global download_folder, move_folder
--
on run
	set download_folder to (path to desktop)
	set move_folder to choose folder with prompt "Choose destination:"
end run
--
on idle
	tell application "Finder"
		try
			set new_files to every file of download_folder whose ¬
				name extension is in (file_extensions as alias list)
		on error
			set new_files to first file of download_folder whose ¬
				name extension is in (file_extensions as alias as list)
		end try
		move new_files to move_folder
	end tell
	return 2
end idle

This script is saved as a stay open application. It checks the download folder every two seconds. You might need to add some error handling like for instance if your downloads take a long time.

gl,

Kel,

thanks for your reply. If you hook this script up to your automatic tasks in your image capture, does it run after pictures are downloaded. I think my script does what your does as well, but the problem is that I don’t want to make it a folder action or constantly monitor my folder, but rather I want image capture to trigger this script as it should, at least based on what Image capture interface looks like (didn’t find much documentation on this app)>

Thanks

Marek

Hi Marek,

I’m not sure about Image Capture, but I think it’s used to process pictures when a camera is connected. I thought you meant that you’re downloading pictures from the internet. In this case, Image Capture won’t automatically process pictures I think. I’ve never heard about anyone using this app to run a script.

gl,

Hi Kel,

if you launch Imaga Capture with camera connected you will see that its UI offers to pick an Automated task from a list. Apple has already provided some pre-built apps which are in the menu. So I thought as long as it’s .app it should do, but not so with my script. I think it’s a good idea to have a script (.app) linked straight to Image capture. It saves me definitely time.

Thanks

Marek

Hi Marek,

You can try using an open handler.

on open file_list
– do something with the list of files
end open

If this works, then file_list will be a list of references to the pictures.

Good Luck,

Thanks, I will try that. Although how does Image capture know what file_list I am talking about? anyways I still think that even if you want to use just a simple

display dialog “Hello World”

It should still work as long as I save the script as .app, but it doesn’t for me. Interestingly I’ve tried to create a samll HelloWorld app in AppleScript studio and it worked nicely. So maybe I will just have to write my script and wrap it into app through AppleStudio. Not something I was planning, but hey it works, why not.

Thanks

Marek