A little help understanding why? [coercion]

I have some code:

set a to the name of contents of folder choose folder --this folder is full of ".jpg" files
set b to a as alias
display dialog b

it displays: can’t make into type string. why?

I’m confused when you can get names from a folder and write them to a list and when to use as alias.

what I want to do is take folder a (with .jpg files)
and compare them to folder b (with copies of the same files)
and write the missing files to c

thanks!

the “display dialog” command is expecting a string. You are sending it an alias. While it is true that Applescript will coerce many classes into other classes automatically, it won’t coerce everything. Change:

display dialog b

into:

display dialog (b as string)

and you should see the path of the chosen folder.

Hope this helps,
Brad Bumgarner, CTA

The following routine should do pretty much what I think you’re aiming for, DE. (In case it helps, I’ve added comments to describe the result of each statement.)

set originals_folder to choose folder with prompt "Choose originals folder:" --> alias
set duplicates_folder to choose folder with prompt "Choose duplicates folder:" --> alias
set new_duplicates_folder to choose folder with prompt "Choose new duplicates folder:" --> alias

tell application "Finder"
	set duplicate_names to name of files of duplicates_folder --> list of names (of the previously duplicated files)
	set uncopied_files to files of originals_folder whose name is not in duplicate_names --> list of Finder references (of the missing files)
	duplicate uncopied_files to new_duplicates_folder --> list of Finder references (of the newly duplicated files)
end tell

Thanks Guys!

It was helpful

–Sorry I never sent a message this long

Totally Confused!

I have this script posted below. I target a .txt file which contains paragraphs of various file names like this:

jpeg1.jpg
jpeg2.jpg
jpeg3.jpg
etc.
etc.

This converts the text doc to applescript list. If I uncomment my “Display dialog” at the end I can see that each file is cycling thru and filling the variable “thename” just fine. It works great if my .txt file has a small list or if my SOURCE_IMAGE folder contains a few images. However, when I target a .txt doc with a large amount of files or if my SOURCE_IMAGE folder has alot of files (more than 25) the script gives me this error:

Finder got an error: Can’t set alias “Macintosh HD:Users:de:Desktop:DESTINATION” to file named "

– Let’s try again

Totally Confused!

I have this script posted below. I target a .txt file which contains paragraphs of various file names like this:

jpeg1.jpg
jpeg2.jpg
jpeg3.jpg
etc.
etc.

This converts the text doc to applescript list. If I uncomment my “Display dialog” at the end I can see that each file is cycling thru and filling the variable “thename” just fine. It works great if my .txt file has a small list or if my SOURCE_IMAGE folder contains a few images. However, when I target a .txt doc with a large amount of files or if my SOURCE_IMAGE folder has alot of files (more than 25) the script gives me this error:

Finder got an error: Can’t set alias “Macintosh HD:Users:de:Desktop:DESTINATION” to file named "

Can anyone tell me why my whole message won’t post???