Re: Mac vs unix Carriage returns on a text file format
Re: Mac vs unix Carriage returns on a text file format
- Subject: Re: Mac vs unix Carriage returns on a text file format
- From: Bill Chase <email@hidden>
- Date: Sun, 3 Apr 2005 15:20:19 -0400
Forget all this hocus-pocus and download Linebreak.
http://maccrafters.com/lbc/
It is without a doubt the best utility to handle this operation and if
you must, scriptable.
Once the preferences are set you can D&D a directory on it or set it to
also do the sub-directories.
-Bill
On Apr 2, 2005, at 5:15 PM, kai wrote:
On Fri, 1 Apr 2005 10:04:07 -0800, Christopher Nebel wrote:
On Mar 31, 2005, at 2:56 PM, Dennis Jones wrote:
I had a similar problem with files I downloaded from an IBM mainframe
which came in with DOS type line ends. ...
Don't forget, AppleScript's "paragraph" elements of text are line-
ending-agnostic. If you have a glob of text that's formatted
whichever way (even a mix), "paragraph 4" will get you the fourth
paragraph regardless.
The practical significance of Chris's point shouldn't be
underestimated, since this feature makes converting line-breaks a
breeze - regardless of existing or required line endings. In the
'changeLineBreaks' handler of the script/droplet below, for instance,
the text conversion operation (which would otherwise need rather more
in the way of "search and replace" type routines) is reduced to just a
couple of lines or so:
------------------
property fileTypes : {"TEXT"} -- modify as required
property extTypes : {"txt"} -- modify as required
property conversionList : {"DOS: \"\\r\\n\"", "UNIX: \"\\n\"",
"Macintosh: \"\\r\""}
property breakList : {return & (ASCII character 10), ASCII character
10, return}
property currConversion : {conversionList's item 3}
property currBreak : breakList's item 3
to changeLineBreaks at f
set o to open for access f with write permission
if (get eof o) > 0 then
set text item delimiters to currBreak
set t to (read o)'s paragraphs as string
set text item delimiters to {""}
set eof o to 0
write t to o
end if
close access o
end changeLineBreaks
to chooseConversion()
tell (choose from list conversionList with prompt ¬
"Convert line breaks to:" default items currConversion)
if it is false then error number -128
set currConversion to it
end tell
repeat with n from 1 to 3
if conversionList's item n is in ¬
currConversion then exit repeat
end repeat
set currBreak to breakList's item n
end chooseConversion
on selectionWas over n
set b to {"Cancel"}
set x to "The selection contains "
set z to " suitable for conversion."
if n is 0 then
set y to "nothing"
else
set y to "only " & n & " item"
if n > 1 then set y to y & "s"
set b's end to "Continue"
set z to z & return & return & ¬
"Continue with conversion?"
end if
tell application (path to frontmost application ¬
as Unicode text) to display dialog x & y & z ¬
buttons b default button (count b) with icon 2
end selectionWas
to open l
set r to {}
repeat with i in l
tell (info for i) to if file type is in fileTypes or ¬
name extension is in extTypes then set r's end to i
end repeat
tell (count r) to if it < (count l) then my (selectionWas over it)
chooseConversion()
repeat with f in r
changeLineBreaks at f
end repeat
end open
to run
set f to choose file of type fileTypes with prompt ¬
"Please choose a file to convert:"
chooseConversion()
changeLineBreaks at f
end run
------------------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden