Hi ans
Since I arrive home late I don't have a chance to fully debug this scrript.
But one thing that I notice immediately is this line
- Code: Select all
set backupFolder_as to choose folder with prompt "Select backup folder:" as string
Adding a log statement I verified that the variable/property
backupFolder_as is class "alias" not class "text". The as string command only converts "Select backup folder:" to a string (which it already was)
The way Applescript works is that once defined, an alias always points to the same file or folder, even if you move it and I think even if you rename it. I think it is actually a reference to the inode of the file. (For this reason, an alias can only be defined for a file or folder which already exists. The string can be written, but trying to convert it to type alias will fail.)
Now what happens when I use the script to create a
Backup folder, use it a few times and then delete it, the i]Backup[/i] folder is moved to Trash. But it still exists, and has the same inode. The next time I run the script, it copies the image file to the Backup folder in the Trash.

Not useful.
Then if you empty the Trash, the alias refers to a folder that doesn't exist, and the final line that uses
backupFolder_as as a target location crashes.
So the first fix is to rewrite that line like this
- Code: Select all
set backupFolder_as to get (choose folder with prompt "Select backup folder:") as string
Now
choose folder creates an alias, which is immediately converted to a string. Now when the folder is deleted, the alias does not follow to the Trash.
This far I have debugged.
Then I think after the else statement, I would modify the try structure like this
- Code: Select all
try
--if the previously created backup folder has been deleted or moved, the alias cannot be created
--the error that results causes the script to ask for a new folder
get backupFolder_as as alias
on error
set backupFolder_as to get (choose folder with prompt "Select backup folder:") as string
end try