Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create Windows-safe filenames via AppleScript System
If you have a file server that you are connecting to using SMB, and that also shares files with Windows users, then there are some naming rules that you should follow to make sure your files are readable by Windows users. (This also applies when copying files to FAT32 formatted disks for Windows users to access). So I wrote an AppleScript to do just that.

It will accept any combination of files or folders using drag and drop, run through the entire list of files and folders, and rename them according to two lists you can edit. The first list is characters that can cause problems in filenames, and the second list is characters that can cause problems if they are the first or last character in a file or folder name. You can change the substitute character, and the two lists, in the script properties.

It will preserve extensions and handle duplicate name conflicts. It also presents a dialog at the end showing how many files were checked, and how many files were renamed.

As always, copy the code and paste into a new AppleScript in Script Editor, and save as an Application with no splash screen. Also, as with anything like this, use at your own risk. I've tested it pretty well, it's fully commented and has error handing for the file rename routine, but I can't guarantee that it won't erase your hard drive.

[robg adds: I risked my hard drive :) and tested this script with a few oddly-named files and folders. It renamed them all without any issues, and it seems my hard drive is still full of data.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[11,206 views]  

Create Windows-safe filenames via AppleScript | 13 comments | Create New Account
Click here to return to the 'Create Windows-safe filenames via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Compilation error
Authored by: hamarkus on Jan 31, '07 08:08:06AM

I get the following error on compilation/save:
"Syntax Error
A unknown token can't go after this "}". "
The curled bracket is the one on the first line.



[ Reply to This | # ]
Compilation error
Authored by: Fritz865 on Jan 31, '07 09:17:07AM

I get the same syntax error noted in the first comment.



[ Reply to This | # ]
Compilation error
Authored by: joostjodel on Jan 31, '07 10:03:14AM

Yes, Im having the exact same error in Script editor 2.1.1 on 10.4.8.

Any suggestions for correction?



[ Reply to This | # ]
Compilation error - solution
Authored by: joostjodel on Jan 31, '07 10:32:09AM
Although I really know nothing at all about Apple Scripting, I made it work...
1) Apparently the file up for download has some wrong end of line marks which look like ¨ but should be . So change all end of line errors you encounter in compiling the Applescript with this sign.
2) Then follow the hint someone else posted here before about changing ? into is not. Then you're ready to go!
And I want to add I find this an extremely useful script! Thanks!! I'll rate it a 5 anyway :)

[ Reply to This | # ]
Got it working
Authored by: hamarkus on Jan 31, '07 10:37:55AM

To fix the error on the first line, do not download the file but open the link to it in a browser window and copy the content from there (works at least with Camino). The problem was a strange return/new line character at the end of the first line which the browser shows correctly but the neither of my text editors does.

The second error (line 60) is fixed as noted below by replacing the ? with 'is not' (probably the unequal sign works as well). Somewhere between the OP and posting the script on the website, file/character encodings got probably messed up.



[ Reply to This | # ]
Problem line 60
Authored by: lolopb on Jan 31, '07 09:03:56AM

Very interesting script but I have an error when compiling :

"Error: -2471. Expected "then", etc. but found unknown token."

and it shows line 60, the "?" :

"if theName ? newname2 then -- if the name has been changed"

Is it really a question mark ?

Thanks in advance



[ Reply to This | # ]
Problem line 60
Authored by: capitalj on Jan 31, '07 09:19:51AM

It looks like that "?" should be a "≠"



[ Reply to This | # ]
Problem line 60
Authored by: lolopb on Jan 31, '07 10:59:04AM

Thanks, I should have tried to read the code, but, I hate reading AppleScript, in fact, sorry.

Reading it makes it appear logical, that's true.

I promise to boot my brain next time.

Thanks again,



[ Reply to This | # ]
Create Windows-safe filenames via AppleScript
Authored by: ADent on Jan 31, '07 09:47:30AM

Thank You.

I looked around awhile ago and couldn't find any good affordable solutions for this.



[ Reply to This | # ]
Create Windows-safe filenames via AppleScript
Authored by: aphasiac on Jan 31, '07 09:59:25AM
There is a mistake in the script. the line:

if theName ? newname2 then -- if the name has been changed

must be changed to:

if theName is not newname2 then -- if the name has been changed

After that works great - very very useful script!

[ Reply to This | # ]
Create Windows-safe filenames via AppleScript
Authored by: mactotum on Jan 31, '07 01:27:29PM
I applied the fix and it works great. I've given it my own pet name: "FileNeuter" (pardon the pun).

Here's the CORRECTED text (as per the previous post):

http://brak.rice.edu/downloads/FileNeuter/FileNeuter.txt

I also compiled the script and zipped it up with a plain AppleScript file and the text file. Download the whole she-bang here:

http://brak.rice.edu/downloads/FileNeuter/FileNeuter.zip

Hope this helps!

PS> A BIG, BIG THANK YOU TO THE AUTHOR!!

[ Reply to This | # ]
KopyMac
Authored by: digitol on Jan 31, '07 11:11:43PM
I have attempted this with an app I wrote called KopyMac.
http://www.versiontracker.com/dyn/moreinfo/macosx/18491



[ Reply to This | # ]
Updated script now with name shortening
Authored by: jtrott on Sep 17, '07 02:51:27PM
I've updated the script to properly handle bundles (don't rename anything inside them) like .app and .oo3 bundles. I've also added an option to reduce the length to under 32 characters which is enabled by default. To disable this, edit the script and change the setting to false.
You can download the new version from:
[link:]http://homepage.mac.com/jtrott/FixFileandFolderNames.zip

[ Reply to This | # ]