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 <[email protected]> wrote:
> [email protected]
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/bbedit/topics>
> Google
> Groups
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview>
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email/#!overview>
> Topic digest
> View all topics
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/bbedit/topics>
>
> - help on notes project <#m_-1846469767624989676_group_thread_0> - 1
> Update
>
> help on notes project
> <http://groups.google.com/group/bbedit/t/e783874069af7684?utm_source=digest&utm_medium=email>
> Andrew McDowell <[email protected]>: 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
> Back to top <#m_-1846469767624989676_digest_top>
> You received this digest because you're subscribed to updates for this
> group. You can change your settings on the group membership page
> <https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!forum/bbedit/join>
> .
> To unsubscribe from this group and stop receiving emails from it send an
> email to [email protected].
>
--
This is the BBEdit Talk public discussion group. If you have a feature request
or need technical support, please email "[email protected]" rather than
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/bbedit/CALLXKrQj2REQTtSMZHDLetqcsrXfobNYgK6p6w0LB9GKqXjTeA%40mail.gmail.com.