Applescript to Find, Shorten File Names

I am a novice apple-scripter. I am trying to help a friend move all of his audio files to an external hard drive. The problem is that many of the file names are more than 31 characters long, and they won’t copy. I’m hoping to write an apple script that will find and truncate these file names (after I use another applescript to copy the original filename into the comments field).

Please let me know if you have any sugestions or code snippets!

Thanks!

Ann

Ann:

No sweat; but first a little clarification. What do you mean by ‘comments field?’ Are these audio files all within iTunes or some other program? I am also curious about which OS your friend’s machine is running. If it is OS X 10.4.x, we can use Smart Folders to simplify the task.

I do not believe that it is necessary to truncate all the filenames. I understand that you are a beginning scripter, and all of us here hope that you will stick with it and enjoy it as much as we do. There are easy ways to copy and/or move these files and keep the original filenames. Here is only one example:

set a to choose file
tell application "Finder" to set aaa to a's name --To use the [cp] command in the shell, you need a full path, including filename.  The variable [aaa] is the filename, regardless of length.
set aa to quoted form of (POSIX path of a) --Makes the chosen file readable to the shell.
set b to path to documents folder as Unicode text --Simply an example of a folder to place all the files.
set c to quoted form of (POSIX path of (b & aaa)) --Builds the new path [b & aaa] and makes the string readable to the shell
do shell script "cp " & aa & " " & c --Copy it, baby!

This will allow you to choose a file, and then it will copy that file to your Documents Folder, using the shell, which does not care how long the filename is. The basic underpinnings of this script are easily altered to copy an entire folder of files to another folder on a separate drive.

This is by no means meant as a complete solution, rather an example of how easy it can be. We all anxiously await your reply.

Craig,

Thanks for the reply. Yes, the application is iTunes. He’s running 10.3.x, so Smart Folders are not an option. I will play around with what you’ve given me, and will be back if I have questions.

THANKS!

hey, i have a similar problem, but rather than save the long names i really do want to shorten them!

A client has supplied filenames with * as a limiter in the filename
“01_three sisters*Thrown cut and altered forms with inlayed slip patterns=560x300x130.jpg”
I wish to return

“01_three sisters” as the file name

any help?

Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.4)

Truncate them to how long? Truncate them in place, or as you move them? How do you want to handle duplicates?