DOS line breaks

I’m wanting to create/write text files using Applescript that will also display correctly on Windows machines.

Is it possible to set DOS line breaks using Applescript? Anyone care to post any other hints that might be useful for this project?

If you have BBedit this is an option in the Save menu. You can convert to Dos, Unix, etc.

You may have seen this already, but this is a Terminal script that can be ran from AS to convert:


You can do it with AppleScript. Look for a search/replace subroutine at this site. All you need to do then is replace carriage return (Mac) with carriage return + linefeed (dos).


Thanks for the input. So am I right in thinking something along these lines would work, or have I must understood your hint?

set searchTerm1 to “carriage return”
set replaceTerm1 to “carriage return + linefeed”
searchReplaceText(searchTerm1, replaceTerm1, sometextFile)

on searchReplaceText(searchTerm, replaceTerm, theText)

set searchTerm to searchTerm as list
set replaceTerm to replaceTerm as list
   set theText to myMP3_files as text
set oldTID to AppleScript's text item delimiters
repeat with i from 1 to count searchTerm
	set AppleScript's text item delimiters to searchTerm's item i
	set theText to theText's text items
	set AppleScript's text item delimiters to replaceTerm's item i
	set theText to theText as text
end repeat
set AppleScript's text item delimiters to oldTID

return count

end searchReplaceText


Yes, that looks like it will work except for your parameters. The subroutine might cause problems in some cases but for your’s it looks ok. Here’s how to set up the parameters:

set t to “a,b,c
set s to return
set r to return & (ASCII character 10)
ReplaceText(s, r, t)

Editted: also this line looks wrong:

set theText to myMP3_files as text


Do shell script "awk 'sub("$", "\r")' " & unixfile & " > " & winfile

i just realized theother day that dosunix and unixdos were a package on fink so i use that now.

Thanks for your help with this, Kel (and others).

Replacing “return” with “return & (ASCII character 10)” seems to have done the trick.

I was aware of the BBEdit and fink options for doing this switch, but in this case the completed script will need to run on machines which may or may not have anything more than the standard OSX apps installed. So being able to perform the find/replace in a “native” manner was just was I was after.

For others checking this thread, do check out the other options provided above, as they are also ways of achieving the same end.

Thanks for all your help.