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

0 Members and 1 Guest are viewing this topic.

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Renaming and Filing Images
« on: November 04, 2015, 02:01:11 PM »
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.


Code: [Select]
on open droppedfiles
   
    repeat with afile in droppedfiles

     
            --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
                   
                    --TELLING FINDER TO RESET APPLESCRIPT'S TEXT ITEM DELIMITERS IF THERE'S AN ERROR
                on error
                    set AppleScript's text item delimiters to oldDelims
                   
                end try
            end tell
           
            --FILING THE IMAGES
            tell application "Finder"
                activate
               
                set fileToMove to afile
                set fileToMove_Name to name of fileToMove as string
                set fileExt to name extension of fileToMove as string
               
                --DUPLICATE FILE TO WEB CONVERT FOLDER ON R DRIVE
                try
                    if fileExt is "tif" then
                        duplicate fileToMove to alias "Volumes:sdrive:IMAGES_FROM PREPRESS:z_DEBORAH_CONVERT and FILE:"
                    else
                        move fileToMove to alias "Volumes:server1:Advertising Department:5_ADVERTISING DEPT - PREPRESS:1_ADV IMAGE PROCESSING:2_PROCESSING:Processing:Scripts:Convert:"
                    end if
                   
                    --Moving file to the "File Manually in RDRIVE & 1_4c IMAGES folder" inside the Processing Folder if there is an error
                on error
                    move fileToMove to alias "Volumes:server1:Advertising Department:5_ADVERTISING DEPT - PREPRESS:1_ADV IMAGE PROCESSING:2_PROCESSING:Processing:Scripts:File Manually in RDRIVE & 1_4c IMAGES:" with replacing
                end try
               
               
               
                --ONTO FILING INTO THE 1_4C IMAGES FOLDERS
                try
                   
                    --DECLARING LISTS OF STRINGS OF CHARACTERS FOR THE COMPUTER TO LOOK FOR
                   
                    --AG Files
                    set AG00string to {"AG00", "AG01", "AG02", "AG03"}
                    set AG04string to {"AG04", "AG05", "AG06", "AG07", "AG08", "AG09"}
                    set AGAstring to {"AGA", "AGB", "AGC", "AGD", "AGE", "AGF", "AGG", "AGH", "AGI", "AGJ", "AGK", "AGL", "AGM", "AGN", "AGO", "AGP", "AGQ", "AGR", "AGS", "AGT", "AGU", "AGV", "AGW", "AGX", "AGY", "AGZ"}
                    set AG_Astring to {"AG_A", "AG_B", "AG_C", "AG_D", "AG_E", "AG_F", "AG_G", "AG_H", "AG_I", "AG_J", "AG_K", "AG_L", "AG_M", "AG_N", "AG_O", "AG_P", "AG_Q", "AG_R", "AG_S", "AG_T", "AG_U", "AG_V", "AG_W", "AG_X", "AG_Y", "AG_Z"}
                   
                    --BI Files
                    set BI0string to {"BI0", "BI1", "BI2", "BI3", "BI4", "BI5"}
                    set BI6string to {"BI6"}
                    set BI7string to {"BI7"}
                    set BI8string to {"BI8"}
                    set BI9string to {"BI9"}
                    set BIAstring to {"BIA", "BIB", "BIC", "BID", "BIE", "BIF", "BIG", "BIH", "BII", "BIJ", "BIK", "BIL", "BIM", "BIN", "BIO", "BIP", "BIQ", "BIR", "BIS", "BIT", "BIU", "BIV", "BIW", "BIX", "BIY", "BIZ"}
                    set BI_Astring to {"BI_A", "BI_B", "BI_C", "BI_D", "BI_E", "BI_F", "BI_G", "BI_H", "BI_I", "BI_J", "BI_K", "BI_L", "BI_M", "BI_N", "BI_O", "BI_P", "BI_Q", "BI_R", "BI_S", "BI_T", "BI_U", "BI_V", "BI_W", "BI_X", "BI_Y", "BI_Z"}
                   
                                       
                    --MOVING THE ACTUAL FILES TO THE 1_4C IMAGES FOLDERS
                   
                    --Moving AG files to 1_4c IMAGES Folders
                    if AG00string contains (text 1 thru 4 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:AG-high res images:AG00 - AG03 - HI RES:"
                    else if AG04string contains (text 1 thru 4 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:AG-high res images:AG04 - AG09 - HI RES:"
                    else if AGAstring contains (text 1 thru 3 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:AG-high res images:AGA - AGZ - HI RES:"
                    else if AG_Astring contains (text 1 thru 4 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:AG-high res images:AGA - AGZ - HI RES:"
                       
                        --Moving BI files to 1_4c IMAGES Folders
                    else if BI0string contains (text 1 thru 3 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BI0 - BI5 - HI RES:"
                    else if BI6string contains (text 1 thru 3 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BI6 - HI RES:"
                    else if BI7string contains (text 1 thru 3 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BI7 - HI RES:"
                    else if BI8string contains (text 1 thru 3 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BI8 - HI RES:"
                    else if BI9string contains (text 1 thru 3 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BI9 - HI RES:"
                    else if BIAstring contains (text 1 thru 3 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BIA - BIZ - HI RES:"
                    else if BI_Astring contains (text 1 thru 4 of fileToMove_Name) then
                        move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BIA - BIZ - HI RES:"
                       
                        --Moving All Other Files to the "File Manually in 1_4c IMAGES" Folder inside the Processing Folder
                    else
                        move fileToMove to alias "Volumes:server1:Advertising Department:5_ADVERTISING DEPT - PREPRESS:1_ADV IMAGE PROCESSING:2_PROCESSING:Processing:Scripts:File Manually in 1_4c IMAGES:"
                    end if
                   
                    --Moving Files to the "File Manually in 1_4c IMAGES" Folder inside the Processing Folder if there is an error
                on error
                    move fileToMove to alias "Volumes:server1:Advertising Department:5_ADVERTISING DEPT - PREPRESS:1_ADV IMAGE PROCESSING:2_PROCESSING:Processing:Scripts:File Manually in 1_4c IMAGES:"
                end try
               
            end tell
    end repeat
end open


Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Renaming and Filing Images
« Reply #1 on: November 05, 2015, 03:29:12 AM »
Hi! At a glance, you seem to double set the name of the file to move:

Code: [Select]
                    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

Wouldn't this be the culprit?
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Renaming and Filing Images
« Reply #2 on: November 05, 2015, 08:30:21 AM »
Thanks. It's still giving me the -4960 error, so maybe there's a second culprit?

Code: [Select]
on open droppedfiles

repeat with afile in droppedfiles


--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

--TELLING FINDER TO RESET APPLESCRIPT'S TEXT ITEM DELIMITERS IF THERE'S AN ERROR
on error
set AppleScript's text item delimiters to oldDelims

end try
end tell

--FILING THE IMAGES
tell application "Finder"
activate

set fileToMove to afile
set fileToMove_Name to name of fileToMove as string
set fileExt to name extension of fileToMove as string

--DUPLICATE FILE TO WEB CONVERT FOLDER ON R DRIVE
try
if fileExt is "tif" then
duplicate fileToMove to alias "Volumes:sblain$:IMAGES_FROM PREPRESS:z_DEBORAH_CONVERT and FILE:"
else
move fileToMove to alias "Volumes:nas:Advertising Department:5_ADVERTISING DEPT - PREPRESS:1_ADV IMAGE PROCESSING:2_PROCESSING:Melissa Processing:Scripts:Convert:" with replacing
end if

--Moving file to the "File Manually in RDRIVE & 1_4c IMAGES folder" inside the Processing Folder if there is an error
on error
move fileToMove to alias "Volumes:nas:Advertising Department:5_ADVERTISING DEPT - PREPRESS:1_ADV IMAGE PROCESSING:2_PROCESSING:Melissa Processing:Scripts:File Manually in RDRIVE & 1_4c IMAGES:" with replacing
end try



--ONTO FILING INTO THE 1_4C IMAGES FOLDERS
try

--DECLARING LISTS OF STRINGS OF CHARACTERS FOR THE COMPUTER TO LOOK FOR

--AG Files
set AG00string to {"AG00", "AG01", "AG02", "AG03"}
set AG04string to {"AG04", "AG05", "AG06", "AG07", "AG08", "AG09"}
set AGAstring to {"AGA", "AGB", "AGC", "AGD", "AGE", "AGF", "AGG", "AGH", "AGI", "AGJ", "AGK", "AGL", "AGM", "AGN", "AGO", "AGP", "AGQ", "AGR", "AGS", "AGT", "AGU", "AGV", "AGW", "AGX", "AGY", "AGZ"}
set AG_Astring to {"AG_A", "AG_B", "AG_C", "AG_D", "AG_E", "AG_F", "AG_G", "AG_H", "AG_I", "AG_J", "AG_K", "AG_L", "AG_M", "AG_N", "AG_O", "AG_P", "AG_Q", "AG_R", "AG_S", "AG_T", "AG_U", "AG_V", "AG_W", "AG_X", "AG_Y", "AG_Z"}

--BI Files
set BI0string to {"BI0", "BI1", "BI2", "BI3", "BI4", "BI5"}
set BI6string to {"BI6"}
set BI7string to {"BI7"}
set BI8string to {"BI8"}
set BI9string to {"BI9"}
set BIAstring to {"BIA", "BIB", "BIC", "BID", "BIE", "BIF", "BIG", "BIH", "BII", "BIJ", "BIK", "BIL", "BIM", "BIN", "BIO", "BIP", "BIQ", "BIR", "BIS", "BIT", "BIU", "BIV", "BIW", "BIX", "BIY", "BIZ"}
set BI_Astring to {"BI_A", "BI_B", "BI_C", "BI_D", "BI_E", "BI_F", "BI_G", "BI_H", "BI_I", "BI_J", "BI_K", "BI_L", "BI_M", "BI_N", "BI_O", "BI_P", "BI_Q", "BI_R", "BI_S", "BI_T", "BI_U", "BI_V", "BI_W", "BI_X", "BI_Y", "BI_Z"}


--MOVING THE ACTUAL FILES TO THE 1_4C IMAGES FOLDERS

--Moving AG files to 1_4c IMAGES Folders
if AG00string contains (text 1 thru 4 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:AG-high res images:AG00 - AG03 - HI RES:"
else if AG04string contains (text 1 thru 4 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:AG-high res images:AG04 - AG09 - HI RES:"
else if AGAstring contains (text 1 thru 3 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:AG-high res images:AGA - AGZ - HI RES:"
else if AG_Astring contains (text 1 thru 4 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:AG-high res images:AGA - AGZ - HI RES:"

--Moving BI files to 1_4c IMAGES Folders
else if BI0string contains (text 1 thru 3 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BI0 - BI5 - HI RES:"
else if BI6string contains (text 1 thru 3 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BI6 - HI RES:"
else if BI7string contains (text 1 thru 3 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BI7 - HI RES:"
else if BI8string contains (text 1 thru 3 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BI8 - HI RES:"
else if BI9string contains (text 1 thru 3 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BI9 - HI RES:"
else if BIAstring contains (text 1 thru 3 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BIA - BIZ - HI RES:"
else if BI_Astring contains (text 1 thru 4 of fileToMove_Name) then
move fileToMove to alias "Volumes:server1:Advertising Department:2_IMAGES - HIGH RES FOR PRINT:1_4c IMAGES:BI-high res images:BIA - BIZ - HI RES:"

--Moving All Other Files to the "File Manually in 1_4c IMAGES" Folder inside the Processing Folder
else
move fileToMove to alias "Volumes:nas:Advertising Department:5_ADVERTISING DEPT - PREPRESS:1_ADV IMAGE PROCESSING:2_PROCESSING:Melissa Processing:Scripts:File Manually in 1_4c IMAGES:"
end if

--Moving Files to the "File Manually in 1_4c IMAGES" Folder inside the Processing Folder if there is an error
on error
move fileToMove to alias "Volumes:nas:Advertising Department:5_ADVERTISING DEPT - PREPRESS:1_ADV IMAGE PROCESSING:2_PROCESSING:Melissa Processing:Scripts:File Manually in 1_4c IMAGES:"
end try

end tell
end repeat
end open

Offline mbornbach

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: Renaming and Filing Images
« Reply #3 on: November 05, 2015, 03:23:59 PM »
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.
Code: [Select]
set name of afile to newName

Here's the full simplified code:

Code: [Select]
on open droppedfiles

repeat with afile in droppedfiles


--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


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


--FILING THE IMAGES
--DUPLICATE FILE TO WEB CONVERT FOLDER ON R DRIVE
duplicate afile to alias "Volumes:sblain$:IMAGES_FROM PREPRESS:z_DEBORAH_CONVERT and FILE:"

--Moving file to the "File Manually in RDRIVE & 1_4c IMAGES folder" inside the Processing Folder if there is an error
on error
set AppleScript's text item delimiters to oldDelims
move afile to alias "Volumes:nas:Advertising Department:5_ADVERTISING DEPT - PREPRESS:1_ADV IMAGE PROCESSING:2_PROCESSING:Melissa Processing:Scripts:File Manually in RDRIVE & 1_4c IMAGES:" with replacing
end try


end tell
end repeat
end open

Offline Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Renaming and Filing Images
« Reply #4 on: November 13, 2015, 05:52:15 AM »
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.

Is this the behaviour you're expecting?
« Last Edit: November 16, 2015, 02:52:04 AM by Jean-Marie Schwartz »
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =