C-Command Software Forum

File extension and applescript

Would it be possible to write a script that would change the file extension of selected files?

I presume that in principle it would be easy enough, but I know that Finder likes to protest this kind of change. Could one write it so as to placate the vigilant Finder?

If so, would it be possible to adapt the PDF-PDFD script ?

(You probably wonder why. I have a reason that would make little sense to most.)

Yes, that should be possible for filenames that EagleFiler allows you to change. I recommend starting with the Replace in Filenames script.

Thanks, Michael
May I ask: What should replace

“filename” in

“set theName to theRecord’s filename” ?

You’ll want to keep that part, as it reads the current filename into theName. If you want to do a find/replace, you could change this line:

set theSource to my promptForString("Enter text to find in the filenames:")


set theSource to ".c"

and change this line:

set the theReplacement to my promptForString("Enter replacement text:")


set theReplacement to ".m"

This would, for example, replace “.c” in the filename with “.m”. Or you could change this line:

set filename of theRecord to *my replace(theName, theSource, theReplacement)*

and replace the italicized part with whatever you want the new name to be.

I know I’m pushing my luck with your patience :wink:
but this leaves the extension intact. I notice also that in the EagleFiler Records List if I double-click on a filename and remove the extension, the extension gets automatically replaced and remains unchanged.

There’s a kind of extension demon, I think. Doesn’t like meddling, but maybe if we leave a cookie (and cocoa) in just the right spot?

Maybe I’ve got something wrong and this works for you…but it seems that there is a distinction between filename and file extension…


Well, this is where it would help if you could tell me more specifically what you’re trying to do. For some file types, EagleFiler won’t let you change the extension, as a safety feature. An RTF file that doesn’t end in .rtf or .rtfd would not be openable. For others, like plain text files, it should let you do whatever you want.

I am pushing my luck…

Trying to change plist to txt (or rtf).

EagleFiler imports plist fine and shows them as plain text files, but for another purpose I need them to be txt (or rtf). Just trying to use EagleFiler in ways it probably wasn’t intended, but why not?
In any case it’s not terribly important. There are other ways to remove this cat’s skin.

Thanks again.

Most plist files are not stored as plain text; EagleFiler only displays them that way. It treats plist files as a distinct type of record (as shown by the Kind column). Renaming a binary plist to .txt won’t convert the format of the data; it will just confuse applications trying to open the file. Likewise, if you rename it to .rtf, probably no rich text editors will accept it. It sounds like you want to convert the file’s data, not just change its name.

I can open plist files with TextEdit of course and when I do I see all kinds of stuff in addition to some real text.
I have a bunch of these and am not trying to convert the contents, only trying to salvage. So turning these into .txt would work for me because then I could get these open in another app that could do some work on them. EagleFiler is great because it enables me to see the text (by which I mean meaningful ordinary language), but it can’t do other things. So I was hoping to use it as an intermediary to change the extension and I’m not concerned about losing the format. (I’m working with copies anyway.)
I realize that this is not orhtodox and perhaps for good reason. I’m just trying to find a way to get the text from these files more conveniently. Yes, I could copy paste or the like, but elsewhere I can concatentate many such files—if they’re txt or rtf—and then do some automated find/replace and the like.
So: Is it possisble to alter the extension?

Thanks again

This is why you should use a program that understands property lists, such as Property List Editor or TextWrangler. Or use plutil to convert the binary property lists to text format.

It’s not clear to me why that’s necessary. Most text editors will let you open files regardless of the extension.

If you just want to rename copies of the files, why not use a utility designed for that purpose, such as Name Mangler?

No, EagleFiler will not let you change the extension of plist files.

Ok. I thought maybe EagleFiler could do what Name Mangler does—and I didn’t know about Name Mangler. Its perfect.
Thanks so much for all of your help. Sorry to put you through all of this for such a simple thing…