Script to find and copy files

I’m completely new to writing Applescripts, and I’m looking for some help getting started. This seems pretty ambitious for an early attempt, but it will save me a huge amount of work. I need a script to help me search my company’s photo library and fill orders for photos. We receive requests in a variety of forms, so I think that converting each request to a plain text file would be the most consistent way to create input for the script. I was thinking to save the script as a droplet, then drop the text file on it to run. If there’s a better way to do it I’m certainly interested. The text file would contain a series of item numbers separated by line breaks like this (though it may contain over 200 items):


Here are the steps we use to do this manually, but I understand a script may not follow exactly the same process.

¢ Start with first item number.
¢ Open a mounted server (the photo library).
¢ In that window, open a category folder indicated by the first digit of the item number.
¢ In that window, search for a folder whose name matches the item number. If there isn’t a match, move on to the next item number.
¢ If a matching folder is found, open it and look for a .psd file named for the item number (21160-10.psd for example). If no .psd is found, move on to the next number.
¢ If the .psd is found, copy it to a holding folder on a local drive. This will always be the same holding folder, so it can be written directly into the script. There’s no need to choose a folder on running the script.
¢ Repeat with every item number.
¢ If it could at the end create a text file in the holding folder showing the item numbers not found that would be helpful, but not necessary.

What I would actually like help with is outlining the logic to make the script work, breaking it to sub-routines, and suggesting some relevant topics to study. I’ll then do the research and try to write the script myself. It already looks like I’ll need to read up on “try”, “if”, and “repeat” statements among other things. I think I’ll understand it better and learn more that way. Let me know if I need to provide any other info or clarify anything. Thanks in advance for any help anyone can give.

Model: PowerMac G5
Browser: Firefox
Operating System: Mac OS X (10.4)

First, if you’re new to applescripting I would start with doing some of the tutorials on this website. You can find them in the “unscripted” section located here… There’s a bunch of tutorials labeled “Applescript Tutorial for Beginners” that you might want to start with. These would give you a good base of knowledge to start with. They don’t take very long to do.

Here’s some topics you’ll need to pay particular attention to for your task.

  1. Reading from text files and writing a text file
  2. Once you read in the text, you’ll want to convert it to a list so you can easily work with the text… so you’ll need to understand lists.
  3. Your searching can be done using applescript commands for Spotlight
  4. Finder commands will help you move the files

The project isn’t too difficult if you understand applescript, but since you’re starting from scratch you really need to do the tutorials first. Then break your project into manageable pieces, then in the end you can put everything together. From reading your post it seems you have a good grasp about what you need.

Good luck.

I found the info I think I need for reading text files and converting the data into a list, so that part’s good for now.

I was beginning to investigate the search process when I had an idea. Do I even need to search for the files I need? Their location really isn’t much in question; the item number could be used to fix the file path. Would it be more efficient to use the “exists” command to verify the files existence rather than searching for it? Some of what I’ve read indicates that searching with a script can be slow. I think I can see how telling the script where to look, letting it look there for file, then acting or moving on depending on what it finds would be faster than a search.

Does anyone have any thoughts on which approach would work better?

Model: PowerMac G5
Browser: Firefox
Operating System: Mac OS X (10.4)

Definitely, if you know where all the folders reside then just set the path to those folders as a variable. Then to get to each individual folder add the folder name to the variable so you’ll have the full path to each folder you want to search.