I’m trying to turn kai’s excellent PDF collection script into an Image Collection Script. Here is his script:
property tgtFolder : alias "ExampleDisk:ExampleFolder:PDFs"
property suffX : ".pdf"
on uniqueName for currName against nameList
if currName is not in nameList then return currName
set baseName to currName's text 1 thru -((count suffX) + 1)
set n to 1
set testName to baseName & "-" & n & suffX
repeat while testName is in nameList
set n to n + 1
set testName to baseName & "-" & n & suffX
end repeat
testName
end uniqueName
on adding folder items to this_folder after receiving added_items
tell application "Finder"
set nameList to name of tgtFolder's files
repeat with currItem in added_items
set currName to currItem's name
if currName ends with suffX then
set newName to my (uniqueName for currName against nameList)
set nameList's end to newName
if currName is newName then
move currItem to tgtFolder
else
set currItem's name to " "
move currItem to tgtFolder
set currItem's name to newName
end if
end if
end repeat
end tell
end adding folder items to
For one file type it works perfectly, but if I change
property suffX : ".pdf"
to
property suffX : {".jpg", ".jpeg", ".tif", ".tiff", ".gif", ".png", ".eps", ".ai"}
it will compile fine but does nothing at all. I’ve also tried changing the first 3 instances of suffX to
name extension of (info for thefile)
and again, it compiles fine but does nothing. Also, I’d like to use this script on a lab of Macs in my school. Is there any way to change the path of tgtFolder to a folder inside the current user’s Documents folder regardless of their username/who is logged in? IE: each user would have their own collected images folder in their own Documents folder.
Any help anyone could give would be extremely appreciated. I’m afraid I’m a bit (understatement) of an Applescript newbie.
Hiya Jacques,
Thank you for solving the folder bit of my problem. I tried your edited script and it does the same thing my edited copy did. The screen “pulses” to let me know the folder action script is running, but nothing happens; no files are moved. Again, thank you for helping me with the folder bit!
Jacques…YOU ARE A GENIUS! Thank you so much for your help! The script works perfectly now and it’s so useful. Again Jacques, thank you a ton for all your help and thanks to kai for the original script. You both are amazing.
Here’s the finished script for anyone that’s interested.
(*
Image - Collect & Move
This Folder Action script is designed for use with Mac OS X version 10.4 and higher. It is untested
on earlier versions of OS X but should work on Mac OS X version 10.3 and higher.
This Folder Action script should be placed in "/Library/Scripts/Folder Action Scripts/" before use.
This Folder Action handler is triggered whenever a file or folder is copied or moved to the Desktop
folder. For this Folder Action to work, the user MUST first create a folder named "Images" on their
Desktop. Currently, the folder is "Images" but it can be named anything, just edit the name below
and make sure it matches the folder name you've created. You can also change it from being on
your desktop to a folder inside your documents folder by changing "(path to desktop folder as string)"
to "(path to documents folder as string)".
The list of file extensions that will be processed can be changed, added to or you can delete any
extension you want. You could also change all the extensions and create, for example, a text
collection script by using {".txt", ".html", ".html"}. You can also duplicate this script, rename
it, again for example, "HTML - Collect & Move" and attach both scripts to your Desktop folder
and have Images collected in one place and Text files collected in another place.
Special thanks to kai and Jacques from http://applescript.net/ . Enjoy! ;)
*)
property tgtFolder : (path to desktop folder as string) & "Images" as alias
property suffX_list : {".jpg", ".jpeg", ".tif", ".tiff", ".gif", ".png", ".eps", ".ai"}
global suffX
on uniqueName for currName against nameList
if currName is not in nameList then return currName
set baseName to currName's text 1 thru -((count suffX) + 1)
set n to 1
set testName to baseName & "-" & n & suffX
repeat while testName is in nameList
set n to n + 1
set testName to baseName & "_" & n & suffX
end repeat
testName
end uniqueName
on adding folder items to this_folder after receiving added_items
tell application "Finder"
set nameList to name of tgtFolder's files
repeat with currItem in added_items
set currName to currItem's name
set suffX to "." & currItem's name extension
if suffX is in suffX_list then
set newName to my (uniqueName for currName against nameList)
set nameList's end to newName
if currName is newName then
move currItem to tgtFolder
else
set currItem's name to " "
move currItem to tgtFolder
set currItem's name to newName
end if
end if
end repeat
end tell
end adding folder items to