Author
Topic: Renaming and Filing Images (Read 2410 times)

I have an applescript droplet that renames and files images. When I drop the images onto this droplet, it will rename the first one and then give me an error -4960, stopping the script before it files even one image. If I try dropping images onto the droplet a second time after they've been renamed and caused an error, the script then cooperates and files the images. If I do the renaming and filing script as two separate droplets instead of one, it works perfectly. I'm assuming I have something wrong that is preventing the renaming and filing parts of the script from working together. It may be one of those obvious things that I just can't see, but I'd really appreciate it if someone could help me see why it's not working.

--USING THE FINDER TO RENAME THE FILE, ADDING _s_4c to THE IMAGE NAME tell application "Finder" activate set fileToMove to afile set fileToMove_Name to name of fileToMove set fileExt to name extension of fileToMove

set oldDelims to AppleScript's text item delimiters

try --ELIMINATING _4c on IMAGES THAT ALREADY HAD _4c IN FILE NAME BEFORE PROCESSING if name of fileToMove contains "_4c" and name of fileToMove does not contain "_s_4c" then set AppleScript's text item delimiters to {"_4c"}

--ELIMINATING DOUBLE _s_4c on IMAGES THAT ALREADY HAD _s_4c IN FILE NAME BEFORE PROCESSING else if name of fileToMove contains "_s_4c" then set AppleScript's text item delimiters to {"_s_4c"}

--FOR IMAGES THAT DIDN'T HAVE _s_4c IN FILE NAME BEFORE PROCESSING else if name of fileToMove does not contain "_s_4c" or "_4c" then set AppleScript's text item delimiters to {"."} end if

set fileName to name of fileToMove --> ex. Disneyland.tif set nameWithoutExtension to first text item of fileName --> Disneyland set newName to nameWithoutExtension & "_s_4c" & "." & fileExt --> Disneyland_s_4c.tif set name of fileToMove to newName

--RESETTING APPLESCRIPT'S TEXT ITEM DELIMITERS AND NAME set AppleScript's text item delimiters to oldDelims set name of fileToMove to fileToMove_Name

--USING THE FINDER TO RENAME THE FILE, ADDING _s_4c to THE IMAGE NAME tell application "Finder" activate set fileToMove to afile set fileToMove_Name to name of fileToMove set fileExt to name extension of fileToMove

set oldDelims to AppleScript's text item delimiters

try --ELIMINATING _4c on IMAGES THAT ALREADY HAD _4c IN FILE NAME BEFORE PROCESSING if name of fileToMove contains "_4c" and name of fileToMove does not contain "_s_4c" then set AppleScript's text item delimiters to {"_4c"}

--ELIMINATING DOUBLE _s_4c on IMAGES THAT ALREADY HAD _s_4c IN FILE NAME BEFORE PROCESSING else if name of fileToMove contains "_s_4c" then set AppleScript's text item delimiters to {"_s_4c"}

--FOR IMAGES THAT DIDN'T HAVE _s_4c IN FILE NAME BEFORE PROCESSING else if name of fileToMove does not contain "_s_4c" or "_4c" then set AppleScript's text item delimiters to {"."} end if

set fileName to name of fileToMove --> ex. Disneyland.tif set nameWithoutExtension to first text item of fileName --> Disneyland set newName to nameWithoutExtension & "_s_4c" & "." & fileExt --> Disneyland_s_4c.tif set name of fileToMove to newName

I tried simplifying the code down to the part that seems to be giving me problems in an attempt to solve the part that is keeping the script from working. I'm still getting that -4960 error right after the script renames the images but before it moves them. The interesting thing is if the image already has _s_4c at the end of the filename, the script does work.

If I remove the following line, the script works for all images regardless of how they are named, but then the images that did not have _s_4c at the end are not renamed correctly.

--USING THE FINDER TO RENAME THE FILE, ADDING _s_4c to THE IMAGE NAME tell application "Finder" activate set fileExt to name extension of afile set oldDelims to AppleScript's text item delimiters

try --ELIMINATING _4c on IMAGES THAT ALREADY HAD _4c IN FILE NAME BEFORE PROCESSING if name of afile contains "_4c" and name of afile does not contain "_s_4c" then set AppleScript's text item delimiters to {"_4c"}

--ELIMINATING DOUBLE _s_4c on IMAGES THAT ALREADY HAD _s_4c IN FILE NAME BEFORE PROCESSING else if name of afile contains "_s_4c" then set AppleScript's text item delimiters to {"_s_4c"}

--FOR IMAGES THAT DIDN'T HAVE _s_4c IN FILE NAME BEFORE PROCESSING else if name of afile does not contain "_s_4c" or "_4c" then set AppleScript's text item delimiters to {"."} end if

set fileName to name of afile --> ex. Disneyland.tif set nameWithoutExtension to first text item of fileName --> Disneyland set newName to nameWithoutExtension & "_s_4c" & "." & fileExt --> Disneyland_s_4c.tif set name of afile to newName

I've run your code. (I've also created locally, that is on my Desktop, both folders "File Manually in RDRIVE & 1_4c IMAGES" and "z_DEBORAH_CONVERT and FILE").I processed a tenish pictures. They all were renamed with the tail _s_4c (correctly?) and moved to the folder "File Manually in RDRIVE & 1_4c IMAGES".Then I've run it again chosing those renamed pictures and they were all duplicated to the folder "z_DEBORAH_CONVERT and FILE" with no change in the file names.