Name and file type changing script - Does it exist?

Hi folks,
I am a complete newbie to Automator and have tried without success to create the following script. I wonder if any of you can tell me if a script exists (as I cant seem to find it…) I have 18k+ images that were in Canto Cumulus - I am taking them over into Aperture and have managed to embed metadata into the imagery using Mediadex. I then created a folder structure on my desktop that resembled the original nested folder structure within Mediadex and dragged the appropriate imagery into each folder. (the idea being that this will be an easy way to create nested keywords in Aperture) This worked fine, BUT the images are not named with .jpg at the end and do not open with any app until I manually change each image to .jpg .
I am trying to find an automator script that will do this for me (and also change the names of the files that are in the internal nested folders - ie. I might have a structure such as this:

Spain/Grenada/Alhambra/SP/02/01/192/-

I would like the script to change the file to

SP:02:01:192.jpg if possible and to change all other files within the folder nest in the same way. (note that we are deleting the “-” symbol so as not to confuse Unix machines (I believe!?)

Would you know if such a beast exists? Or if I could write one (with my non-existent programming skills!)

There is an existing applescript that will change the file type by adding .jpg at the end, but it only works on the frontmost folder, does not really do everything that I want it to and would be incredibly slow to use for all my folders! It is called “Add to File Names”

Many many thanks for your help

Model: MacPro twin processor
AppleScript: 2.2.1
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)

Canned scripts for stuff like this are typically hard to find, based on specific needs of persons in multi-treed folder structures. That said, these things are pretty simple to construct, once the rules have been figured out. It looks like you just taking a dash and creating a full filename, is that correct? You are not actually wanting the filename to have all the colons, are you?

If you could be just a shade clearer on how things are organized now, and how you want them to end up, this should not take long to produce.

Hi Craig,
many thanks for your help.

My file structure typically looks like this:

Stock
UK
London
City
St. Pauls
Lloyds
Westminster
Houses of Parliament
Westminster Abbey
France
Paris
La Defense
Grande Arche
Clignancourt
Market
Loire
Blois
Chateau
Azay le Rideau
Chateau

and the file names are typically SP/02/01/192/-

So you can see that there is a lot of nesting. I would probably run the script on one country at a time to ensure that all went smoothly…

I constructed this file structure when I knew nothing about computer systems and have since discovered that there are problems in using the slash character…
(UNIX filenames only contain letters, numbers, and the _ (underscore) and . (dot) characters. All other characters should be avoided. The / (slash) character is especially important, since it is used to designate subdirectories. Also the ; character which is used in all VMS filenames can create difficulties in UNIX - avoid it like the plague! )

So I felt that whilst adding .jpg I should also change the naming structure of the files to be UNIX friendly - I was under the impression that a colon was friendly to Mac, Unix and MS, but I am no expert. An underslash could be used if this were more multi-system friendly…

In addition many of the files (though not all) have “-” characters on the end of the file name (this were originally there to simply notify me that there was only one copy of the original transparency) (another file might be called for example PT/01/03/71/3 (which tells me that I have three copies of the slide) (but this is fairly unimportant data… it doesn’t really matter if I do not know how many copies I have…) (and some files have an “A” or a “B” on the end because of mistakes by the person scanning the imagery originally)
If it is problematical to identify this scenario then we could always change all “/” and “-” characters to “_” However that might mean that some files end in __.jpg and I am not sure if that is allowed either!

Perhaps the easiest thing would be a script that first strips all files ending in “-” of the character, then strips all files ending in “/” of the character (which they might do if the “-” character is removed first), then converts all “/” characters to “_” and finally adds .jpg to the end of ALL files

Does this sound very complicated? Is it easier to do with two or more scripts? I am trying to get my limited understanding around it, but it looks as though it is the sort of thing that 'Automator" was built to do?

once again, many many thanks for your help

All the best

Matthew Weinreb

www.thearchitecturalphotographer.com

Matthew:

Typically, underscores and dots are your best bets for delimiters in filenames; colons are also folder separators on the Mac.

Automator is fun, but it really designed to perform rote type stuff on a nice, neat single folder of files, at least that is my impression. It can certainly do file renaming, just not with this kind of semi decision making ability.

Try this script on one of your folders; it should work:

set fol to choose folder
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "_"
tell application "Finder"
	repeat with apf in (get every file in fol)
		set old_name to every word of (apf's name as text)
		set apf's name to ((old_name as text) & ".jpg")
	end repeat
end tell
set AppleScript's text item delimiters to astid

If it indeed works like you want, this next modification will go through and process ALL files in an entire nested folder arrangement on a single top folder. Be patient if you do this, scripting the Finder can be slow, but I am not versed well enough in faster methods to be of any help:

set fol to choose folder
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "_"
tell application "Finder"
	repeat with apf in (get every file in entire contents of fol)
		set old_name to every word of (apf's name as text)
		set apf's name to ((old_name as text) & ".jpg")
	end repeat
end tell
set AppleScript's text item delimiters to astid

Good luck, I hope this works (or at least gets close).

Craig, you are a genius and a star. I couldn’t go to bed without trying this. It works PERFECTLY. Thanks so much - I will duly make my contribution to MacScripter.
It is so reassuring in this world to reach out for help on something and to have it given freely from 1000s of miles away. Have a wonderful Christmas :):):slight_smile:

all the best
Matt W