Re: Digest for bbedit@googlegroups.com - 1 update in 1 topic

87 views
Skip to first unread message

David Weinberger

unread,
Dec 17, 2023, 9:06:44 AM12/17/23
to bbe...@googlegroups.com
Just for fun, I asked ChatGPT 3.5  about this. 

Here's my prompt to it: 

I have an AppleScript project. I have a set of text files. I am going to go through them and mark the text blocks I want to extract with ";;" as a delimiter. Each text block will begin with some header text and a date. I will create a document that is a list of the pathnames of all the files I want to process; let's call that the "manifest." I will create a blank document named "All Extracts.txt". I would like the AppleScript to go through the manifest, extract each delimited text block, and append it to "All Extracts.txt"

It responded:

-- Set the path to the folder containing your text files
set folderPath to "YourFolderPath"

-- Create or open "All Extracts.txt" for writing
set outputFile to (open for access (folderPath & "All Extracts.txt") with write permission)

-- List of file paths in the manifest
set manifest to {"/path/to/your/file1.txt", "/path/to/your/file2.txt"} -- Add your file paths here

-- Process each file in the manifest
repeat with filePath in manifest
    -- Open the current file
    set inputFile to open for access filePath

    -- Read the content of the file
    set fileContent to read inputFile as «class utf8»

    -- Close the current file
    close access inputFile

    -- Extract text blocks based on ";;" delimiter
    set textBlocks to paragraphs of fileContent
    set extractedText to ""
    set isBlockActive to false

    repeat with lineText in textBlocks
        if lineText starts with ";;" then
            if isBlockActive then
                -- Append the extracted text to "All Extracts.txt"
                write extractedText & lineText & linefeed to outputFile starting at eof
                set extractedText to "" -- Reset for the next block
            else
                set isBlockActive to true
            end if
        else
            if isBlockActive then
                set extractedText to extractedText & lineText & linefeed
            end if
        end if
    end repeat
end repeat

-- Close "All Extracts.txt" after processing all files
close access outputFile

This script assumes that each text block is started with ";;" and ends before the next ";;" delimiter. It extracts the text blocks and appends them to the "All Extracts.txt" file in the same folder as your text files.

Remember to replace "/path/to/your/file1.txt", "/path/to/your/file2.txt" with the actual file paths in your manifest. Also, make sure to back up your data before running any script, especially if it modifies files.

-------

I don't use AppleScript so I don't know if this will work, but my experience with chatGPT so far has been that at least for the sort of simple Python and JavaScript programming I do as a clunky hobbyist, it's usually pretty durn good!

Also, I apologize if I've misunderstood your scenario.

Good luck!



On Sat, Dec 16, 2023 at 10:39 PM <bbe...@googlegroups.com> wrote:
Andrew McDowell <andy...@gmail.com>: Dec 16 08:47AM -0800

- notes project description
- I have a number of notes journals, some up to 100k words, written over
some 30 years. Multiple topics in each file. My project is to extract and
compile all meaningful notes from these journals and split them out by
topic into separate files. Everything will be plain text, at least
initially (I'll have to sanitize some Word files). My thought is to use
BBEdit and Apple Scripts to accomplish this, as it's the only thing I've
found that shows any promise at all. If anyone has a better idea I'm
listening.
- I would prep the notes journal files into delimited text blocks as seen
below. Following that is my pseudo code attempt at a script. I'm a beginner
with Apple Scripts and with BBEdit. I am not a coder but willing to learn
enough scripting, regex, etc to do this. Help is appreciated. Let me know
if I can be clearer.
- If this works I'm sure I'll find other things to automate for this or
other projects.
-----
- proposed form for 'prepped source file' (notes journal)
- misc (unwanted) text
- filename1 (target file for the following clip)
- ;; (beginning delimiter)
- heading, date
- text body
- ;; (end delimiter)
- misc (unwanted) text
- filename2
- ;;
- heading, date
- text body
- ;;
- misc text
- etc ... to end of file
-----
- proposed (pseudo code) script
- find 1st filename
- index that file to front
- select & copy delimited text (;; text ;;)
- append selection to target file
- find next filename in source file & repeat
- no more filenames?
- done.
-----
- maybe only an end delimiter is needed, if filename may serve as beginning
delimiter?
- If anyone offers a script, please translate it for me (I'm a dummy)
- Or if there's a better way...
Thanks, Andy
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to bbedit+un...@googlegroups.com.

Andrew McDowell

unread,
Dec 18, 2023, 10:44:51 PM12/18/23
to BBEdit Talk
Thanks David,
I seem not to have stated my project clearly enough. I do not want to gather text blocks from several files and consolidate them into one ("AllExtracts.txt") in your proposal. It's rather opposite, actually. I want to collect text blocks on various topics from ONE file (at a time) and distribute them by topic to various receiving files, indicated by various file names I will place just ahead of the various text blocks in the source file. Hope that's clear. If not, I'll try again.

I do have several of these source files, but I anticipate prepping them and processing them one at a time. Maybe I'll reach a point where I'll want to batch process several at a time, but not initially.

DavidWeinberger

unread,
Dec 20, 2023, 8:05:50 AM12/20/23
to BBEdit Talk
Sorry to have misunderstood. But perhaps you can describe your project to chat.openai.com and see how it does in generating the AppleScript. If it gets it wrong, you can always tell it what it misunderstood and it will "happily" try again.
Reply all
Reply to author
Forward
0 new messages