Adding extensions - PC cross platform friendly

Hi all, I’m a novice applie scripter, I’ have dabbled in it here and ther but using PC’s I never really had a chance to play with it until now. I have been hired as Web guy and all around systems / network guy at a design firm.

The deal is that they are Mac based, but my web dept. uses PCs. The delema is that I’m trying to make the network more universal, I’ve started by removing all “/” from file and folder names and replacing them with “-” which works well. But now I have a differnet problem.

Many mac users have no need to add the .ext (extension) to their files since the OS handles this. As you can tell there are many files on the server that I can’t open to edit with the appropriate PC program because of this. I have gotten around this problem simply by heading to a nearby G5 and adding the extension to the file depending on it’s creator type.

Is there a way to automate this via applescript? I would like to know if applescript can look at a file’s creator & type and add the appropriate extension to the file if it’s name does not already contain it.


Quark file → Quark File.qxd
Picture.tif → Ignor file has extention
Photoshop file - photoshop file.psd

I hope my example give the proper Idea. This type of scripting is advanced for me but with time I can pick it up, for now I would like to ask for your help in this project. I will make my life easier and my network more Universal for our employees.

Thank you in advance – Raccoon =^_^=

Yes that’s possible - here a simple example for a file type rename script:

tell application "Finder"
	set theFolder to choose folder
		set theList to every file of folder theFolder whose file type is "XPRJ"
	repeat with theFile in theList
		set name of theFile to (name of theFile) & ".qxd"
	end repeat
end tell

I can see what you are doing in this script Dominik but I also notice that I didn’t see any way of ignoring files that already have an extension on them so some results from this script may give you…

Quark.qxd → Quark.qxd.qxd

How would you fix this?

BTW: thanks for the input.

Raccoon =^_^=

Sorry Racoon, my first example was just a simple “How to” not a ready made script :wink:

Jacques catches the double extension error but there may be more errors - for examle may your users already have given wrong extensions (“.QXD”, “.quark” …)

here a further attempt:

tell application "Finder"
	set theFolder to choose folder
	set theList to every file of folder theFolder whose file type is "XPRJ"
	set olddelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ""
	repeat with theFile in theList
		set theExtension to name extension of theFile
		considering case
			if (theExtension = "") then
				set name of theFile to (name of theFile) & ".qxd"
			else if (theExtension ≠ "qxd") then
				set name of theFile to ((characters 1 thru (((length of theExtension) + 1) * -1) ¬
					of (name of theFile as string)) as string) & "qxd"
			end if
		end considering
	end repeat
	set AppleScript's text item delimiters to olddelims
end tell

But probably you’ll need some more error handling for a perfect script - for example this error isn’t handled yet:
file 1: quark1.qxd
file 2: quark1
→ renaming will have the same result :frowning:

Have you tried to find a ready made script? (here or google) I’m pretty sure there are already good solutions for this job out …



OSX DOES have file extensions like the PC. They should (for the most part) map to the same extensions a PC uses (.ai on a Mac is .ai on a PC, .qsd on a PC is .qxd on a Mac).

Many times they are not visible in the Finder but they are there. For example in Adobe apps, when you save or export there’a a checkbox in the lower left corner that says “Hide Extension”. Doing this will give the appearance of having no extension but it’s really there. Also, if you go into the Finder preferences, there’s an option to show all file extensions. With this checked you will see the “hidden extensions” for these files.

Not having run into this as an IT guy (and not being in your situation currently) I cannot guarantee there should be no problem, but the logical answer is t should work without to much hassle.

Good Luck,
Jim Neumann

Hi Jim,

not all applications’ documents need extensions. QuarkXPress is a good example. It still identifies it’s documents by file type. Try it - you can name Quark documents to whatever you want - they will always open with Quark. Even more - Quark does not add an extension to it’s documents by default.
I am not 100% sure but I guess it’s the carbon applications which do not need to have the extensions.