-- This AppleScript is intended for testing the behaviour of -- embedded text strings with regard to end-of-line characters. -- (See the "end-of-line characters" section of the following Unix FAQ: -- http://hayne.net/MacDev/Notes/unixFAQ.html ) -- -- On OS X, it is desirable that text files be saved with Unix-style -- end-of-line characters. -- The Unix 'file' command will report such a file to be: -- "ASCII English text" -- If, on the otherhand, the file is saved with traditional Mac line-endings, -- it will be reported to be: -- "ASCII English text, with CR line terminators" -- -- Note that without the use of the subroutine 'fixLineEndings', this script -- gives different results depending on which tool is used to compile it. -- If the line that invokes 'fixLineEndings' is commented out, -- using "Script Editor" (v 2.1.1) will give Unix line-endings -- while Satimage's "Smile" (v 3.1.9) will give traditional Mac line-endings -- -- Cameron Hayne (macdev@hayne.net) December 2006 -- asks the user to specify a filename for saving on chooseFileForSaving(defaultName) set savePrompt to "Save file as:" set filename to choose file name with prompt savePrompt default name defaultName return filename as string end chooseFileForSaving -- writes the string 'str' to 'filename' on writeToFile(filename, str) set fRef to (open for access file filename with write permission) set eof fRef to 0 write str to fRef close access fRef end writeToFile -- returns the result of running the Unix 'file' command on 'filename' on unixFileCmd(filename) set unixFilename to POSIX path of filename set info to do shell script "/usr/bin/file " & unixFilename return info end unixFileCmd -- returns a string with Unix-style line endings on fixLineEndings(str) set oldTIDs to AppleScript's text item delimiters set theLines to paragraphs of str set AppleScript's text item delimiters to ASCII character 10 set fixedStr to theLines as string set AppleScript's text item delimiters to oldTIDs return fixedStr end fixLineEndings set theString to "Twas brillig, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe." -- comment out the following line to test the behaviour of different tools set theString to fixLineEndings(theString) set filename to chooseFileForSaving("jabberwocky.txt") writeToFile(filename, theString) set fileInfo to unixFileCmd(filename) display alert fileInfo