Hi All,
I’m writing a bit of code to compare the contents of two folders. One ontaining low rez, FPO graphics and the other has the high rez images for use InDesign. The script checks to see if the high rez graphic is in the “finals to place” folder and if it is, it delets the low rez graphic. I’m about 90% there, but i’m running into an error i don’t understand. I realize my code is a little kloogy, but i’m kinda learning as I go.
here’s my code and the error below:
global finals_to_place_path, FPOpath, FPOitem
tell application "Finder"
activate
-- choose FPO folder
set FPOpath to (choose folder with prompt "Choose folder containing FPOs:") as Unicode text
-- choose Finals to place folder
set finals_to_place_path to (choose folder with prompt "Choose folder containing Finals to Place:") as Unicode text
set FPOitem to ""
repeat with i from 1 to number of items in folder FPOpath
set this_item to item i of folder FPOpath
set FPOitem to the name of this_item
-- test to see if the final version exists, then move the low res file to trash
if finals_to_place_path & FPOitem exists then
move FPOpath & FPOitem to the trash
end if
end repeat
end tell
Here’s my error:
Finder got an error: Can’t get item 9 of folder “Pandora:Users:a_mannon:Documents:Art Folder:03 FPO:”.
Any ideas on how to fix it?
Thanks in advance.
-Andrew
Your script uses the count of items in the FPO folder, so say the count is 3
It then check to see if there is a match in the other folder. if there is then it move the FPO file to trash.
Problem is that the count was only done once so it is still 3 but in the folder there is only 2 files left.
so when you script looks for the 3rd item it can not find it because there is no 3rd item.
Try this.
global finals_to_place_path, FPOpath, FPOitem
tell application "Finder"
activate
-- choose FPO folder
set FPOpath to (choose folder with prompt "Choose folder containing FPOs:") as Unicode text
-- choose Finals to place folder
set finals_to_place_path to (choose folder with prompt "Choose folder containing Finals to Place:") as Unicode text
set FPOitem to ""
set the_items to items in folder FPOpath
repeat with i from 1 to number of items in the_items
set this_item to item i of the_items
set FPOitem to the name of this_item
-- test to see if the final version exists, then move the low res file to trash
if finals_to_place_path & FPOitem exists then
move FPOpath & FPOitem to the trash
end if
end repeat
end tell
Mark has already fixed the problem.
I would prefer a loop “repeat with i in L”, which avoids also this problem,
and working with aliases instead of file references
global finals_to_place_path, FPOpath -- actually not necessary
-- choose FPO folder
set FPOpath to (choose folder with prompt "Choose folder containing FPOs:")
-- choose Finals to place folder
set finals_to_place_path to (choose folder with prompt "Choose folder containing Finals to Place:") as string
tell application "Finder"
repeat with i in (get items of FPOpath)
-- test to see if the final version exists, then move the low res file to trash
if finals_to_place_path & name of i exists then
move i to trash
end if
end repeat
end tell
A Finder file reference is a drawn out list item:
{document file “SomeFileName.txt” of folder “Desktop” of folder “ShortName” of folder “Users” of startup disk of application “Finder”} usable only by the Finder.
An alias to a file of any kind is usable anywhere and all you have to do to get it is coerce: ‘as alias’
alias “HDName:Users:ShortName:Desktop:SomeFileName.txt”
The only time this won’t work is if the file doesn’t exist yet and you are doing something to create it.
set f to open for access “HDName:Users:ShortName:Desktop:SomeFileName.txt” with write permission – no alias.