• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Saving BBEdit Text Files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving BBEdit Text Files


  • Subject: Re: Saving BBEdit Text Files
  • From: John Stewart <email@hidden>
  • Date: Fri, 28 Jan 2005 04:41:45 -0500

On 01/27/05 at -0700 Mark Kot said this

>I have a folder named "Databases" on my desktop containing 400+ text
>files saved from a pc.
>
>My current procedure is to:
>
>"Open" them in BBEdit one at a time > select "Save As" > choose
>"Options" > select Macintosh for "Line Breaks" > "Save" > "Replace".
>
>I'd like to use AppleScript to automate this process. I got the
>following script by using the "Record" option, but it obviously is
>incomplete for all the files in the folder.
>
>
>tell application "BBEdit 6.5"
>   activate
>
>         open {file "KOT OS X:Users:mkot:Desktop:
>         Databases:ACU-CL-00.txt"} with LF translation
>
>         save text window 1 to file "KOT OS X:Users:mkot:Desktop:
>         Databases:ACU-CL-00.txt"
>
>         close text window 1
>end tell
>
>Can someone put me on the right track?

Something like this should suffice. There is no real need for BBEdit making the replacements.

Please note, I haven't tested this as a whole and complete script because I don't have a folder full of windows text files. The various parts have been tested and do work. I'm also sure others on the list will give you other ideas. :)

    --> Cut <--
    set lf to ASCII character 10 --  line feed (UNIX)
    set cr to (ASCII character 13) -- carriage return (Mac)
    set crlf to cr & lf -- Windows

    tell application "Finder" to set theFiles to (every file of folder "KOT OS X:Users:mkot:Desktop:Databases:") as alias list

    repeat with aFile in theFiles
        try
            set fRef to open for access (contents of aFile) with write permission
            set fTxt to read fRef
            my doRplc(fTxt, crlf, cr) -- replace for Mac
            set eof fRef to 0
            write fTxt to fRef starting at 0
            close access fRef
        on error
            close access fRef
            tell application "Finder" to set theFile to (name of contents of aFile)
            display dialog "An error occured processing file " & theFile
            error number -128
        end try
    end repeat

    on doRplc(txtStr, srchStr, rplcStr)
        set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {srchStr}}
        set temp to every text item of txtStr
        set AppleScript's text item delimiters to {rplcStr}
        set txtStr to temp as text
        set AppleScript's text item delimiters to oldDelims
        return txtStr
    end doRpl
    --> Cut <--

Any line in this script which starts at the left margin has been wrapped.
You may need to manually append such a line to the end of the preceeding line if it's a "hard" wrap.

JBS
 _______________________________________________
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

References: 
 >Saving BBEdit Text Files (From: Mark Kot <email@hidden>)

  • Prev by Date: Re: Localize weekdays
  • Next by Date: Re: Localize weekdays
  • Previous by thread: Saving BBEdit Text Files
  • Next by thread: Re: Saving BBEdit Text Files
  • Index(es):
    • Date
    • Thread