I have a folder with a few thousand jpg & tif images and a list of about 800 image filenames that looks like
bags of cocaine.tif,Poll Tax panorama.tif,lump of cocaine.tif,smoking crack in spoon.tif,fly agaric,meals on wheels, Hackney,Farm Chemicals 1.jpg,
As you’ll see, some have extensions, some don’t. Some names in the list have no corresponding file in the folder of images. Many of the images in the folder are not named in the list.
Some of the images in the folder are named with the extension but the name in the list has no extension.
I think there are no images in the folder that exist as both tif and also as jpg versions but if there are then selecting either version or both would be fine.
I need to use the list to separate the images that are listed. This could be by giving them a finder label, selecting them or moving them to a subfolder.
I’ve spent the best part of a day failing to grasp enough Applescript to do this - can anyone show me the way?
TIA!
David Hoffman
Model: Mac Pro
AppleScript: 2.2.1
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)
Something like this should work, though you will have to adjust the read file to work with file format that your list is in. Right now it has both labeling and move commands in place. The script will make the sub-folder if it does not exist to move the files into, and the try statement should trap errors if there is a duplicate in the list and you try to label or move it after it has already been moved. This should work as long as the file names do not contain more than one period and this is used only for the extension.
sset OldDelim to AppleScript's text item delimiters
set listFile to choose file
set fileList1 to read listFile as list using delimiter return --reads the file into a variable as a list
set sourceFolder to choose folder
set foundFolder to (sourceFolder as string) & "FoundFiles:"
tell application "Finder"
set FileList2 to every file of sourceFolder as alias list
if not (exists (foundFolder)) then
--makes sub folder named FoundFiles
make new folder at sourceFolder with properties {name:"FoundFiles"}
end if
end tell
repeat with aFile1 in fileList1
set AppleScript's text item delimiters to "."
--we get text item 1 to eleminate the extension if it exists
set aFile1 to first text item of aFile1 as string
repeat with aFile2 in FileList2
set AppleScript's text item delimiters to ":"
-- this gives us the file name
set aFileName to last text item of (aFile2 as string)
set AppleScript's text item delimiters to "."
--eleminates the extension for a 1 to 1 comparison
set aFileName to first text item of aFileName as string
if aFile1 is in aFileName then
tell application "Finder"
try
--sets label 1 = orange
set label index of aFile2 to 1
--moves the file
move aFile2 to alias foundFolder with replacing
on error
--we do nothing because it has already been moved
end try
end tell
end if
end repeat
end repeat
set AppleScript's text item delimiters to OldDelim
I created the list in Script Editor, saved as a text file and it looks like this:
Thanks Jerome. I see how it should work but it’s not working yet. I’m not sure what you mean by “you will have to adjust the read file to work with file format that your list is in.” If I ask for fileList1 I get a list like:
(I’m just working with a small set of dummy files)
What I mean is that the read command will need to be adjusted to match your text file. Based off of the list you posted it is reading the file as one text item, and it looks like you have a text file with comma separated file names. What you need to do is change the delimiter in the read line to match the separating character that you are using in your file. So…
set fileList1 to read listFile as list using delimiter return
becomes
set fileList1 to read listFile as list using delimiter ","
Of course this is all dependent on the type and format of the file that you are reading the list from so that AppleScript know’s how to turn it into a list that it can work with.
Thank you Jerome, I really appreciate the hand holding! This has just run perfectly and sorted all the files into their folder ready for me to work on.
You’ve saved me a great deal of time, thanks again and a brilliant 2009 to you & all.
Welcome to the site and glad to see you found the solution. Look around and you will probably find a lot of other useful information from the community as well.