0

I have an awfully bad habit of working with 100s of open TextEdit files on my macOS desktop, dropping in various bits of content I find or thoughts that I want to keep every day, I've been doing it for years but it is very chaotic in its method.

I like the way that macOS Notes syncs with Gmail and can also stack text documents within its own folder hierarchy. Has there ever been an Automator or AppleScript shared that can take all open and unsaved TextEdit files and append them with firstLine names and place them into the notes app?

Anything close to that would be really really helpful to me!

5
  • Instead of continuing to use TextEdit, why not just use Notes exclusively?
    – Allan
    Commented Apr 10, 2023 at 4:52
  • @Allan I read the question as "how can I migrate 100s of text documents into Notes?". Both TextEdit and Notes are scriptable so this seems to be possible with some programming.
    – nohillside
    Commented Apr 10, 2023 at 13:48
  • I thought so too, @nohillside until I read the last sentence of the second paragraph, the OP wants to take all unsaved TE docs and move them to Notes
    – Allan
    Commented Apr 10, 2023 at 13:54
  • @Allan Same thing, IMHO. Query TextEdit for all open documents, get their text and create notes using the first line as a note title.
    – nohillside
    Commented Apr 10, 2023 at 13:55
  • It sounds like the OP has some clarifications to make! , to me it sounds like he wants to continue moving forward with this workflow of unending TE docs open and unsaved then convert them to Notes via AS
    – Allan
    Commented Apr 10, 2023 at 14:00

1 Answer 1

2

I think this following AppleScript solution is a good starting point for you. The following code will make a new Note with the name and text from each currently opened unsaved document in TextEdit.

use Notes : application "Notes"
use TextEdit : application "TextEdit"

repeat with thisDocument in TextEdit's documents
    if modified of thisDocument then
        make new note with properties ¬
            {name:name of thisDocument, body:text of thisDocument}
    end if
end repeat

NOTE: For some reason, the above code does not always recognize when a document has been modified. If you run into this issue, just use the following code instead… which will make a note of every opened document whether it has been edited or not. This following version will also name the note with the first 2 words of the document rather than the title of the document. If the opened document only has one word, then that will be the name of the new note

use Notes : application "Notes"
use TextEdit : application "TextEdit"

repeat with thisDocument in TextEdit's documents
    try
        make new note with properties ¬
            {name:(word 1 of text of thisDocument & " " & word 2 of text of thisDocument) as text, body:text of thisDocument}
    on error errMsg number errNum
        make new note with properties ¬
            {name:word 1 of text of thisDocument, body:text of thisDocument}
    end try
end repeat
4
  • Picking a sensible name for the note (which currently most likely will be called "Untitled 1" etc) is left as exercise for the reader, I assume :-)
    – nohillside
    Commented Apr 11, 2023 at 19:14
  • 1
    That is assuming all of his opened and edited documents are completely new documents which have never been saved and named. This will also be true if he actually has saved files named "Untitled 1" etc., which are currently being edited. This code addresses every currently open document, previously named and saved or not... Which has been edited and not saved or re-saved.
    – wch1zpink
    Commented Apr 12, 2023 at 2:01
  • I feel one step closer, but still not there. The script above registers the open notes when run as I can see in the AppleScript log history, but it does not append a new name to each textedit document nor does it include a new note within the Note app. error in Log History repliesget modified of item 10 of every document --> false get modified of To have the unsaved TextEdit documents in Notes would be wonderful, but I can be very happy if I find a way to label these with the FirstLine text with a given amount of word count and save to specified folder, any suggestions? Commented Apr 12, 2023 at 13:34
  • Fantastic, this script works a treat, thank you wch1zpink! Commented Apr 14, 2023 at 10:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .