This is part of a larger macro which copies a text (a Bear Note) and saves as RTFD with the first line as a title.
The macro works fine but it slows my workflow because it moves the cursor to highlight/copy the first line and takes time to find and come back to where I was working in the text before the save.
Doesn't Bear's "Export Notes..." already do this? I've just tried, and the suggested file name is the first paragraph of the selected note. Obviously, if you use long titles/first paras in your Notes you'll want to trim that down somehow.
I have been using Bear for many years and have written quite a few Keyboard Maestro macros specifically for Bear.
I often write the draft of document in Bear because of all the advantages of Markdown.
I wrote a KM macro which automates the menu export including adding date time stamp to file, specify directory etc.
When I work, I make a habit of exporting regularly
Recently, I was working on a long and complex document, and suddenly everything disappeared, a know sync problem. I learned that I have to backup (export) the note I am working on more frequently, and then grew tired of the time the export process takes even with automation because of the time it takes to save to directory, give a name etc.
I wanted to create a single current note backup process which was
1- very fast
2- transparent (in the background)
The result if the following macro. It is extremely fast and transparent (works in the background) which much improved my workflow speed. It's night and day compared to note export in the menu.
The only residual problem as explained above is to extract the title without moving the cursor which causes me to lose track of where I was in the text at the time of backup
Note that the filename contains the keyword BearJLRapidBackup. It's simply a way for me to do a search and delete of these temp files. I may write a Hazel rule to do so.
...and you can then strip out any Markdown characters.
If you'd prefer a regex then you play on the fact that KM's RegEx search only returns the first match it finds. If you always start your notes with a heading (of any level) you could use:
Your pattern means "find one or more new-line characters" -- what you want to find is "one or more characters that are not new-line characters", which is what the ^ does.
I put the first line into the variable Local_FirstLine and also deleted the text that was put on the clipboard during the macro. That puts your clipboard back to the state it was before the macro was run.
That's a nice way of doing it if all @ronald needs is the first line. But -- and perhaps I'm reading between the lines too much -- I think that, at some stage, he's copying the whole document and I can see no easy way to get back from a "Select All". Hence the "create your own text placeholder" approach.
It would never have occurred to me that exporting a document required selecting all the text. My impression was the @ronald wanted the first line so he could build a string to use when filling in the Save As of Export dialog box. But if selecting the whole document is necessary, your placeholder solution makes the most sense.
when I use your method, everything works fine at each step using debugger including the variable which I can see with display text after your shell script, except for the last step which is write to file. Do you see any reason for this ?
thank you
This is the path which always worked. It acts like it no longer recognizes the title variable.
~/Documents/Dropbox/JL IMAC backup of important systems files/Bear Notes/%Variable%BearNoteTitle% BearJLRapidBackup %ICUDateTime%EEE, d-MMM-yyyy h-mm%.rtfd
What are you copying twice? Just copy all, extract the first line to a variable, then write the clipboard to a file using that variable in the file name.
You need to output the file path and check it, making sure you haven't included eg trailing returns -- you have set "Trim Results" in the shell script action, haven't you?
You'll probably find the "For Each" method of grabbing the first line both quicker than shelling out (less overhead) and easier to troubleshoot.
An image really doesn't help -- important information is hidden when it extends past the dialog box, we can't see your action options, etc.
What's your account short name? Is it "jronald" as in the comment, or "ronald" as in the path used in the write action? In fact, skip the full path and use the abbreviated version, then you can use the same script with multiple accounts/computers:
~/Documents/Dropbox/JL IMAC backup of important systems files/Bear Notes/%Variable%BearNoteTitle% BearJLRapidBackup %ICUDateTime%EEE, d-MMM-yyyy h-mm%.rtfd
If you're using different backup folders for different machines, leverage the %MacName% token -- and name your computers and backup folders appropriately!
Using a tilde in the pathname , everything works perfectly now.
If you play darts or enjoy axe throwing, I will send you my picture for the target.
Thank you so much !!!!!!