Appending text to files in a folder of .mp3 files

Hi,

I’ve been trying to hack together a script, based on examples from this forum, with little success.

What I’m trying to achieve is to append the following code to the END of the text of each file in a folder of .mp3 files.

Note: append to the code within the file, not the File Name.

“RestrictionsÆéZê~_Tê~_Tê~_Tê~_Tê~_Tê~_Tê~_T”

Naturally, I want to save each amended file, replacing the original.

Any help would be much appreciated.

Bob Stuart
Think Data Pty Ltd
Noosa
Queensland, Australia.

Model: iMac
AppleScript: AppleScript 2.1.2
Browser: Safari 534.57.2
Operating System: Mac OS X (10.7)

Model: iMac
AppleScript: AppleScript 2.1.2
Browser: Safari 534.57.2
Operating System: Mac OS X (10.7)

Something in the lines of :

set fi to open for access file f with write permission
write "12345" to fi
close access fi


should do the trick, as it writes at the end of the file.

set fi to open for access file f with write permission
set i to get eof fi

write "12345" to fi starting at (i + 1)
close access fi

does the same, getting the end-of-file (eof) position. Is this your problem?

Sorry, no. I checked. This is from the Standard Additions Guide:

When a file is opened the file marker is set to the beginning. Subsequent read/write commands will move the marker, until it is closed. When opened again the file marker is reinitialised.
To append you must always use the 2nd M.O., or issue multiple write commands without closing between writes.

Thanks for your response.

Now how do I get it to loop through a folder full of files?

Bob.

Model: iMac
AppleScript: AppleScript 2.1.2
Browser: Safari 534.57.2
Operating System: Mac OS X (10.7)

Here’s what I tried:

set f to “/Users/Bob/Documents/music/some song.mp3”
set fi to open for access file f with write permission
set i to get eof fi

write “12345” to fi starting at (i + 1)
close access fi

The Events/Replies pane says:

tell current application
open for access file “/Users/Bob/Documents/music/some song.mp3” with write permission
→ 47
get eof 47
→ 5
write “12345” to 47 starting at 6
close access 47
end tell

Opening the file in a text editor shows no difference to the original.

Should something have occurred? Or am I barking up the wrong tree?

Regards,

Bob.

I’m not surprised.
I ran a small test on “Say hello” by April Wine (a band, not a female performer).
It opens in Text Edit, and on the last line is this readable text:

I could not paste that line, and had to type it: the board software did not think I had typed anything at all when I pasted it. The encoding of an mp3 file is nothing like plain text.
Are you surprised?

I’ve had no problem pasting text into .mp3 files. I can manually type something after the last line of code and save the file. The file plays as normal.

Bob.

There still may be a text encoding issue. Typing text into the actual file presumably does retain the file’s encoding. Text written by AppleScript clearly uses a different encoding, as written text does not show up.

But I’m out of my depth here. Search this forum for ‘text encoding’. There may also be tutorials or guides in some other section.

Anyway, an mp3 file isn’t text, so it probably does not have the bits that can tell a script what encoding to use for writing.