(Ooops) Applescript doesn't save changes to System Prefs

–This script will run sucsessfully 5 or 10 times then suddenly “variable this_image not defined” appears. Any thoughts or suggestions would be appreciated. Im running panther 10.3.2

property type_list : {“TIFF”, “JPEG”, “PNGf”, “PICT”}
property extension_list : {“tif”, “tiff”, “jpg”, “jpeg”, “png”, “pict”, “pct”}
property counter : “”
property paramList : {“”, “”, “”}

tell application “Image Capture”
quit
end tell
tell application “Finder”
activate
say “Please enter roll number”
set roll_number to display dialog “Enter Roll Number” default answer “xxxxxx-xx-xx” buttons {“OK”} default button 1
make new folder at folder “Original” of folder “Photo System” of startup disk with properties {name:“temp”}
set name of folder “temp” of folder “Original” of folder “Photo System” of startup disk to text returned of roll_number
set a to text returned of roll_number
select folder “Temp” of folder “Photo System” of startup disk
select every item of folder “Temp” of folder “Photo System” of startup disk
move selection to folder a of folder “original” of folder “Photo System” of startup disk
set nameheader to the text returned of roll_number & “-”
set counter to 1 as number

set mainList to "PhotoshopJPEG"
set listchoice to result as text

if listchoice is "PhotoshopGIF" then set paramList to {".gif", "GIFf", "8BIM"}
if listchoice is "PhotoshopJPEG" then set paramList to {".jpg", "JPEG", "8BIM"}
if listchoice is "PictureViewerGIF" then set paramList to {".gif", "GIFf", "ogle"}
if listchoice is "PictureViewerJPEG" then set paramList to {".jpg", "JPEG", "ogle"}

set fileext to text item 1 of paramList
set fileType to text item 2 of paramList
set creatorType to text item 3 of paramList
repeat with typeitem in folder a of folder "Original" of folder "Photo System"
	try
		if counter < 10 then set name of typeitem to nameheader & "0" & counter & fileext
		if counter > 9 then set name of typeitem to nameheader & counter & fileext
		set file type of typeitem to fileType
		set creator type of typeitem to creatorType
	on error errortext
		display dialog "An error has occured with file: " & typeitem & " :- " & errortext
	end try
	set counter to counter + 1
end repeat
open folder a of folder "original" of folder "Photo System" of startup disk
select folder a of folder "original" of folder "Photo System" of startup disk
copy selection to folder "inhouse" of folder "Photo System" of startup disk
say "please wait while images are resized, this may take a few minutes"

end tell
tell application “Finder”
try
set the source_folder to folder a of folder “inhouse” of folder “Photo System” of startup disk
set these_files to every file of the source_folder whose file type is in the type_list or name extension is in the extension_list
repeat with i from 1 to the count of these_files
set this_path to (item i of these_files) as string
tell application “Image Events”
set this_image to open file this_path
scale this_image to size 1280
save this_image
close this_image
end tell
– FINDER ACTIONS SUCH AS MOVE, DUPLICATE, OR DELETE GO HERE
end repeat
on error error_message
display dialog error_message buttons {“OK”} default button 1
end try
end tell
tell application “Finder”
select folder a of folder “inhouse” of folder “Photo System” of startup disk
copy selection to folder “temp” of folder “Photo System” of startup disk

try
	set the source_folder to folder a of folder "temp" of folder "Photo System" of startup disk
	set these_files to every file of the source_folder whose file type is in the type_list or name extension is in the extension_list
	repeat with i from 1 to the count of these_files
		set this_path to (item i of these_files) as string
		tell application "Image Events"
			set this_image to open file this_path
			scale this_image to size 450
			save this_image
			close this_image
		end tell
		-- FINDER ACTIONS SUCH AS MOVE, DUPLICATE, OR DELETE GO HERE
	end repeat
on error error_message
	display dialog error_message buttons {"OK"} default button 1
end try
select folder a of folder "temp" of folder "Photo System" of startup disk
move selection to folder "ftp" of folder "Photo System" of startup disk
close every window
eject disk "NO NAME   "
say "Transfer is complete. please remove the compact flash card now"

end tell

I also had the same error in relation to image events, but worse in that once it stopped working it was difficult to get it to work again, it only seemed to work again after logging out and in again. Making sure Image Events was quit by view the list of processes in Process Viewer and then restarting it was not good enough.

So, I am also looking for suggestions etc.

Kevin

The last time I scripted Image Capture, under Jaguar, it was a pretty buggy app and, the same as you, it dropped random errors.
I’d try the new “Image Events” (just take a look to its dictionary at /System/Library/CoreServices/Image Events.app).

Dear psmith;
I just joined this forum this morning. I have only started learning AppleScript with the intention of creating tools for my own work and the work of other professional digital photographers. This seems to be what you are working towards too.

I would echo the comments of a previous post that Image Capture may not be an application that you want to use for professional work. Image Capture has a bad habit of overwriting previous files with matching names. It really was intended as a consumer level utility.

It seems that Apple has given scripters the new Image Events app & library to overcome these deficiencies for ourselves. I am looking at creating scripts for the entire digital workfow chain from camera to output.

Please contact me to let me know more about your work. There may be some overlap between things that we are working on. Perhaps we might find some areas to collaborate (divide and conquer)javascript:emoticon(‘:)’)
thomas.white@thomaswhitephoto.com

Image Events seems a great tool. However, it only works for me the command-line version (sips). The bg app doesn’t work properly.
If you need lots of power and flexibility (much more than IE) you may take a look to the command-line set of tools ImageMagick.

I added the launch command to each “tell application “Image Events” in the script and ran thru it sucessfully 38times (got bored) mixing 64-512mb of photos copied thru Image Capture to the " temp” location. Its now installed and running in a production enviroment. I still need to account for if’s to make it more mistake freindly and include ftp transfer. How can I i get this to run automatically after downloading from image capture? I saved it as an app and selected it yet nothing happens. I assume im missing a command.

If I know what’re you talking about, perhaps you need an “open” handler. Try this code:

on open teorical_list_of_images
     repeat with i in teorical_list_of_images
          display dialog (i as text)
     end repeat
end open

:?:

Sorry for the double posting - new to the forum still finding my way around…


Just started using System Events and the UI Element Inspector and so on and been having some success with it. However, I wanted to set up scripts that changed my System Preferences for me, so that I could then plug them into iCal and set them going like sort-of GUI cron jobs.

But, it ain’t workin. The script I’m trying to achieve is to open up System Prefs and change the Energy Saver so that the monitor sleeps after 1 min rather than never. The script runs fine (changes the slider, quits System Prefs), but when I open up System Prefs all the settings are back to what they were.

Any ideas?

Cheers,

I use this handler to set the screensaver with UI scipting:

on setScreensaver(NwVal)
	with timeout of 12 seconds
		tell application "System Preferences"
			set current pane to ¬
				pane "com.apple.preference.desktopscreeneffect"
		end tell
		tell application "System Events" to set visible of process "System Preferences" to true
		tell me to do shell script ("sleep " & 2)
		tell application "System Events"
			tell process "System Preferences"
				tell window 1 --"Desktop & Screen Saver"
					tell tab group 1
						click last radio button -- "Screen Saver"
			tell me to do shell script ("sleep " & 1)
						tell group 1
							set value of slider 1 to NwVal --154 --714 experiment with these values !
						end tell
					end tell
				end tell
			end tell
		end tell
	end timeout
end setScreensaver

Some experimenting is needed with values:
e.g. setScreensaver(120) does not set the value to 120 secs.
I haven’t found any rationale in Apple’s settings here - neither the right conversion of seconds → nwVal.

gr.

Eelco Houwink