Copying Images

I am having a problem using the do shell script “Find” command. I have a list of file types that I am recursively search through directories for.

set imageList to {".tiff", ".jpg", ".jpeg", ".png"}

on GatherImages(Type)
	try
		set theSongs to do shell script "/usr/bin/find " & theImagesPath & " -iname " & " *" & Type & " -exec cp {} " & theCopyPath & computerName & LogDate & " \\;"
	on error theErr
		log theErr
	end try
end GatherImages

repeat with imageType from 1 to the length of imageList
	my GatherImages(imageType)
end repeat

when I use the script as it is… nothing is copied because the find command is using “item 1, etc” rather then the file extension

in the result log, the do shell script result… looks like this.

do shell script "/usr/bin/find /Users/myaccount/Pictures/ -iname  *1 -exec cp {} /Users/myaccount/Desktop/myaccount09-23-2005 \\;"

the *1 should be *.tiff, *.jpg, etc?

Use:

repeat with imageType in imageList
my GatherImages(contents of imageType)
end repeat

This will get you items from the list.

btw, the single word “Type” is not a good label for a variable and could cause problems later.

gl,

I still get the same thing. 1 and 2 etc, rather then tiff, jpg.

I read some where about making and accessing a list like this


set theImageList to {a:".tiff", b:"jpg", c:"jpeg"}
set theNumberList to {"a", "b", "c", "d", "e", "f", "g"}

set theImageCount to count theImageList
set theCount to "1" as number
log theCount
if theCount ≤ theImageCount then
	log theCount
	repeat with i from 1 to (count theNumberList)
		tell theImageList
			set theLetter to (item 1 of theNumberList)
			set theType to theLetter of theImageList
		end tell
	end repeat
	set theCount to theCount + 1
end if

but get a script error on “set theType to contents of theLetter of theImageList”. saying it can’t get theLetter of {a:“.tiff”, b:“jpg”, c:“jpeg”}. But if you change the code to “set theType to contents of a of theImageList” then it pulls out “.tiff”. How come a, b,c of theImagelist can’t be a variable?

Hi dmccoy26,

In your ofirst post, your repeat loop’s:

repeat with imageType from 1 to the length of imageList
my GatherImages(imageType)
end repeat

imageType variable will be an integer from 1 to how many items are in imageList. That’s why you’re getting an integer!

If you need to use an index, then to get an item from the list, you would need something like:

set the_extension to item imageType of imageList

Here, you would get ‘item 1 of imageList’, item 2 of imageList’, etc.

There are different variations of the repeat loop. See AppleScriptLanguageGuide.pdf. In my post I used the repeat with item in list. This is easy to use and you may use this unless you need to use the indices from 1 to some integer somewhere else in your script.

About your second post, there are a lot of things you need to know. You cannot directly use a string and use it as a record label! This is what I always say “You cannot make up stuff!”. There is a workaround for using strings to access fields of records. However, there are much better ways to do this. Don’t use the record! :slight_smile: Just use the repeat loop for now.

Please post again if you don’t understand my two posts.

gl,

To clarify, you should try changing your repeat loop to this:

repeat with i from 1 to length of imageList
	my GatherImages(item i of imageList)
end repeat