Delete and Move

Easily.

Select the lines you want to process/move, and trigger this macro.
It should work in any text document in any app.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Cleanup Block of Lines and Move to Top [Example]

-~~~ VER: 1.0    2020-08-28 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Cleanup Block of Lines and Move to Top [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Macro Author: @JMichaelTX

This is just an example written in response to the below KM Forum Topic. You will need to use as an example and/or change to meet your workflow automation needs.

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me.

==USE AT YOUR OWN RISK==

  • While I have given this a modest amount of testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Topic Title: Delete and move

URL: Delete and Move

Post Date: 2020-08-27
Posted By: Klaas1

1 Like

@JMichaelTX: wow, what a post. I have never had such a professional looking reply on any forum - I tip my hat to you for that, sir.

As a 1st feedback:

  • I fully understand that use of the macro is at my own risk. I could not imagine blaming someone who tries to help for something unexpected. Nevertheless, you are right to make it clear.
  • As a 1st step I will turn on the debugger.
  • I will provide feedback after my tests.
  • If, after testing on a number of notes, it works well, is there a possibility to amend the macro such that I can run it on all remaining notes as 1 action? Or is the necessity to select the lines I want to process/move the limiting factor? We'll talk about that after my test feedback.

To answer your last question, this macro should automatically select all the text in the currently open/frontmost note, format the metatext according to your specifications, and paste it all back without needing to manually select the relevant text first:

Format and Rearrange Metatext.kmmacros (3.5 KB)

Running it on this test note:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

<small>**Meta-Data**</small>
<small>Author: </small>
<small>Book: , p. </small>
<small>Original number: n?</small>
<small>Site: []()</small>
<small>Transcluded in: </small>
<small>Note creation date: </small>
<small>Tags</small>: #

gives me these results:

---
Author: 
Book: , p. 
Original number: n?
Site: []()
Transcluded in: 
Note creation date: 
Tags: #
---

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

@JMichaelTX: 2nd feedback.

The macro works as you said. I would like to fine-tune it a bit. I have attached 3 screenshots:

  • an original note, complete with text and the metadata to be moved;
  • that same note after running the macro;
  • that same note again, but how I would really like it to be, i.e. the real effect I would like the move to have.

My comments continue below the 3rd screenshot.
km1 km2 km3

So, the difference between the 2nd and the 3rd screenshot is:

  • 3 dashed between the line Note creation date and the line Tags
  • a blank line below the line Tags
  • 3 dashes below the line Tags
  • a blank line below the 4th <br> at the bottom of the page
  • below that blank line the line **Footnotes**

Regarding **Footnotes**: I know in the screenshot it shows *Footnotes* but that's just the test note; in my real notes there are 2 ** on either side of the word, so nothing needs to be amended there.

Is all this possible?

@gglick: many thanks for your help. What your proposing would be automation pushed even further. I ran the macro, but it did not complete - the debugger shows an error after the 3rd step.

I managed to make a screenshot of the error message, and my comment below that continues.

I also noticed that it cut a piece of the body text, which surprised me.

It's impossible to say what might have tripped up the regex without actual sample text to work with. Screenshots are certainly better than nothing, but in future posts, it would help a great deal if you could include the actual text, preferably enclosed in a code block (you can use the icon that looks like </> in the formatting bar to enclose text in that). I also recommend reading this post and following its suggestions for best results: Tip: How Do I Get The Best Answer in the Shortest Time?

In the meantime, I OCRed your screenshot of the initial test note to try with a tweaked version of the macro that incorporates some of the further requirements you mentioned in your second to last post, and it seems to work for me:

Format and Rearrange Metatext 1.1.kmmacros (4.4 KB)

Results

---
Author: Olivia Fox Cabane
Book: , p. 
Original number: n222
Site: [Blinkist]()
Transcluded in: 
Note creation date: 2015-01-08
---
Tags: #communication #personality #presence #trust #perception

---

There are many ways to appear charismatic, but the 2 main ones are==presence== and the ==power-warmth combination==.
1. Presence
Being aware of what's happening, moment to moment.

In social interactions (*<!--PB:—>//Social connectedness]]*), this means being with the other person completely (*<!--PB:—//Leadership - empathy]]*), and listening to them intently. If you're fully present with others, you will appear charismatic and generate trust, rapport and loyalty.

If you lack presence, the person you're interacting with will likely notice, and might suffer emotionally because they will feel unimportant.
<br>

2. Power and Warmth
Someone powerful but not warm might be impressive but not necessarily charismatic. They might even appear arrogant or cold. And someone warm but not powerful might be likeable, but not charismatic. Rather, they could seem overeager and subservient.
<br>
###
<br>
<br>
<br>
<br>



<br>

*Footnotes*

@gglick thanks for your patience and understanding. I do apologise for not providing the actual text immediately - I was already "proud" of myself to have thought to provide those 3 versions of the different status of the note, albeit as a screenshot. I do understand it is important to have the actual text.

Anyway, the new macro works almost perfectly. The only bit it does not do is:

  • a blank line below the 4th <br> at the bottom of the page
  • below that blank line the line *Footnotes*

Is it possible to amend the macro for that, please?

Here is the full text:

There are many ways to appear charismatic, but the 2 main ones are ==presence== and the ==power-warmth combination==.
1. Presence 
Being aware of what's happening, moment to moment.
 
In social interactions (*<!--PB:-->[[Social connectedness]]*), this means being with the other person completely (*<!--PB:-->[[Leadership - empathy]]*), and listening to them intently. If you're fully present with others, you will appear charismatic and generate trust, rapport and loyalty.
 
If you lack presence, the person you're interacting with will likely notice, and might suffer emotionally because they will feel unimportant.
 <br>
2. Power and Warmth 
Someone powerful but not warm might be impressive but not necessarily charismatic. They might even appear arrogant or cold. And someone warm but not powerful might be likeable, but not charismatic. Rather, they could seem overeager and subservient.
 <br>

###
<br>
<br>
<br>
<br>

---
<small>**Meta-Data**</small>
<small>Author: Olivia Fox Cabane</small>
<small>Book: , p. </small>
<small>Original number: n222</small>
<small>Site: [Blinkist]()</small>
<small>Transcluded in: </small>
<small>Note creation date: 2015-01-08</small>
<small>Tags</small>: #communication #personality #presence #trust #perception 

<br>

*Footnotes*

No problem. Glad to hear the macro is mostly working for you now. Thanks for including the sample text; it really does make it much easier to test. Assuming there are always four <br> above the *Footnotes*, this version should do what you specify:

Format and Rearrange Metatext 1.1.1.kmmacros (4.8 KB)

Results

---
Author: Olivia Fox Cabane
Book: , p. 
Original number: n222
Site: [Blinkist]()
Transcluded in: 
Note creation date: 2015-01-08
---
Tags: #communication #personality #presence #trust #perception

---

There are many ways to appear charismatic, but the 2 main ones are ==presence== and the ==power-warmth combination==.
1. Presence 
Being aware of what's happening, moment to moment.
 
In social interactions (*<!--PB:-->[[Social connectedness]]*), this means being with the other person completely (*<!--PB:-->[[Leadership - empathy]]*), and listening to them intently. If you're fully present with others, you will appear charismatic and generate trust, rapport and loyalty.
 
If you lack presence, the person you're interacting with will likely notice, and might suffer emotionally because they will feel unimportant.
 <br>
2. Power and Warmth 
Someone powerful but not warm might be impressive but not necessarily charismatic. They might even appear arrogant or cold. And someone warm but not powerful might be likeable, but not charismatic. Rather, they could seem overeager and subservient.
 <br>

###
<br>
<br>
<br>
<br>

*Footnotes*

@gglick: yes, that works perfectly now.

I have about 400 notes that need your macro "treatment": is it possible to automate that or is it safer to run the macro manually for each note?

If bulk automation is possible, could you do that or does it represent a lot of work? You have already spent a lot of time on this, esp. with me not providing enough info at the beginning, so I understand if you prefer to leave it at this. Please don't hesitate to say "I stop here". I am already very happy and grateful with the current status, and it will save me a lot of time as it is compared to doing the manipulation manually, which is what I was considering to do.

Glad to hear it. Bulk automation might be very easy, or it might be somewhat finicky, depending on how Obsidian handles its notes. If each note is in an individual, plain text markdown file, and those files are all stored in the same folder, then it would be fairly trivial to modify the macro to go through them all. If they have to be selected manually within Obsidian, it might still be possible, but you would need to provide the exact steps the macro would need to go through them all.

Each note is an individual .md plain text file, and they are all stored in 1 folder.
Below is the contents of such a folder with markdown code.

If you amend the macro for bulk automation, and before I run it I will back up all the files 1st anyway, just in case.

As explained [[Charisma - acquired trait|here]], many famously charismatic people worked hard to learn this behaviour. It is not easy the acquire the image one wants to project. It will often involve discomfort and negativity.

As part of the exercise it is also important to pay attention to these 2 aspects that can and will obstruct charisma building if they are not dealt with. So, how can that be done?

1<sup>st</sup> one has to realise they are expressed both outwardly, i.e. as part of one's [[Charisma and Body Language|body language]], and inwardly. 

To counteract the outward, negative signals:
* **prevent**;
* **recognize**;
* **remedy or explain**.

To counteract the inward, negative signals:
* **dedramatise**;
* **neutralise**.
*<!--PB:-->To the counteracting those inward, negative signals I would add: do not run away from your [[Fear]]s.*

![[Face your fears#Face them]]

So, what do these terms mean in practice?

**Prevent** = to ensure your comfort by planning ahead.
**Recognise** relates to being present: the more present you are, the more aware of your body language you will be. *<!--PB:-->That can best be achieved with [[Mindfulness]].*
The more aware you are, the easier it is to **remedy or explain** the problem.
 
**Dedramatisation** involves interpreting a negative emotion in a way that reduces its impact: imagine the negative emotion is being experienced by people who've already been through a similar experience, especially those you admire, and trust that they experienced the same thoughts and feelings as you.

**Neutralise** your negativity by realizing that <u>your thoughts are not necessarily accurate</u>. We believe our minds perceive reality accurately, whereas, in fact, <u>our minds do not give us a complete and accurate image of reality</u>. Instead, we perceive only the small amount of information that's most relevant and important to us. *<!--PB:-->In other words, our [[Independent thinking|confirmation bias]] works against ourselves too.*

*<!--PB:-->All this boils down to striving for a [[Healthy mind]].*

###
<br>
<br>
<br>
<br>

---
<small>**Meta-Data**</small>
<small>Author: Olivia Fox Cabane</small>
<small>Book: , p. </small>
<small>Original number: n226</small>
<small>Site: [Blinkist]()</small>
<small>Transcluded in: </small>
<small>Note creation date: 2015-01-08</small>
<small>Tags</small>: #personality #discomfort  #mind #planning 

<br>

*Footnotes*

Great, that makes this easy. This version of the macro should modify every file in that folder. All you have to do is point it at the right one (which you can do so easily by clicking the folder button to the right of the "The items in directory" field at the top of the macro):

Bulk Format and Rearrange Metatext.kmmacros (4.7 KB)

And yes, please do back up all your files before running this, just in case.

I downloaded the macro, and only amended 2 things:

  • the hotkey
  • the folder to be treated

The macro group is enabled:

But the macro does not work. When I activate it with Shift-Option-Cmd-X, I just hear a "cloonk".
I checked the .md files in the folder, and they aren't changed.

What happens if you move the macro to the Global Macro group, or any other group that's available in all applications, and close Obsidian before running it?

I moved it to the Global Macro Group.
I did not close Obsidian because that subfolder in ~/Documents is not accessed by Obs; I copied the folder accessed by Obs in order to test the macro.

This time I don't get the "cloonk" sounds, but this notification:

All right, try this version. It should modify the files it can, skip the ones it can't, and present a list of the ones it couldn't when it's done:

Bulk Format and Rearrange Metatext 1.1.kmmacros (8.9 KB)

Assuming that all works as intended, try opening at least one of the files it failed on (all if there aren't too many) and posting the contents of one or two that's representative of the failures here.

I tried again to run it from the Obsidian macro group but it did not run. Transfer to the Global group did the trick. Most of the files seem to have been converted, some were not, though I did not check all the files.

I picked up a few and put the original version and the bungled version in a zipped folder.
Failed.zip (12.2 KB)

Thanks for providing the files; that made it considerably easier to test. This last tweak should hopefully do the trick:

Bulk Format and Rearrange Metatext 1.1.1.kmmacros (9.4 KB)

1 Like

Yes !!! That works perfectly. You're a star.
Many thanks for your help AND your patience.

I have marked this as the solution.
All the best for now, and perhaps we'll meet again.
Cheers.

1 Like

the KM community is among--if not the--most thorough and helpful community i have ever seen. much love to all the superstars here, you know who you are!

1 Like