# Create a Table of Contents from selected files on macOS using Keyboard Maestro

**URL:** <https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008>\
**Category:** Workflows & Templates\
**Created:** [July 9, 2020, 5:00pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008 "2020-07-09T17:00:22Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanjamurphy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/ryanjamurphy/32/334_2.png) [@ryanjamurphy](https://forum.obsidian.md/u/ryanjamurphy)\
**Post date:** [July 9, 2020, 5:00pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/1 "2020-07-09T17:00:22Z")

</div>

Folks have been hoping for a Table of Contents plugin for a while. This isn’t that, but if you’re on a Mac and have Keyboard Maestro, I’ve created a simple macro that will produce a Table of Contents from a selection of files.

To use it, you select a few files in Finder and activate the macro. The macro copies a bulleted list to your clipboard where each line corresponds with each selected file in link format.

E.g., if you have two files named `A.md` and `B.md`, the macro copies the following bulleted list to your clipboard:

```auto
- [[A]]
- [[B]]

```

Here’s what the macro looks like:

 ![Screen Shot 2020-07-09 at 10.59.06 AM](https://forum.obsidian.md/uploads/default/original/2X/6/64f4e168ba4c47087bbff0be31ef577fe95bd891.png)

And [here’s an export for you to install in KM yourself.](https://axle.design/files/_Create-Obsidian-ToC-from-files.kmmacros)

This macro produces the full vault path link for the ToC. A key thing you’ll have to edit for it to work for you is the vault root string. Switch the string `/Users/ryanjamurphy/Dropbox/Materials` with the path to your Obsidian Vault in the Search and Replace action.

If you just want filenames—i.e., you don’t want `[[../some folder/some file]]`—you can swap the Search and Replace action for a Filter action that deletes the path. [Here’s a version of the macro with those changes](https://axle.design/files/_Create-Obsidian-ToC-from-files-no-path.kmmacros).

Enjoy!

---

<div class="post-metadata">

**Author:** ![goodsignal](https://forum.obsidian.md/user_avatar/forum.obsidian.md/goodsignal/32/129_2.png) [@goodsignal](https://forum.obsidian.md/u/goodsignal)\
**Post date:** [July 10, 2020, 3:33am UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/2 "2020-07-10T03:33:33Z")

</div>

This is brilliant!!!  
I want it and I’m remorseful that we’re on different operating systems 😭

---

<div class="post-metadata">

**Author:** ![AutonomyGaps](https://forum.obsidian.md/user_avatar/forum.obsidian.md/autonomygaps/32/2462_2.png) [@AutonomyGaps](https://forum.obsidian.md/u/AutonomyGaps)\
**Post date:** [July 11, 2020, 12:45pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/3 "2020-07-11T12:45:23Z")

</div>

This is absolutely brilliant! Thanks so much.

I’ve set up a SmartFolder (macOS) on the basis of a search for all markdown files opened today in root folder of my main vault. At the end of the day, I can open that SmartFolder, run this macro on all those files, and then paste the list at the bottom of my Daily Page. This gives me a convenient log of all the notes I’ve consulted during the day. It’s also possible to use other search criteria, like “modified today” or “created today”. Also, since the macro reproduces the sort order of the files selected, if I sort the SmartFolder (= Finder search results) by “Last Opened”, the notes are pasted in chronological order of which notes I’ve opened (or, if you prefered, created/modified).

Here’s a screen shot of the SmartFolder criteria, with the three notes that I’ve opened so far today:

 ![Screen Shot 2020-07-11 at 14.17.00](https://forum.obsidian.md/uploads/default/original/2X/9/99b02a5eb91255adbe30fd8ada7e0abafd969087.png)

---

<div class="post-metadata">

**Author:** ![Jeffurry](https://forum.obsidian.md/user_avatar/forum.obsidian.md/jeffurry/32/207_2.png) [@Jeffurry](https://forum.obsidian.md/u/Jeffurry)\
**Post date:** [July 11, 2020, 1:20pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/4 "2020-07-11T13:20:53Z")

</div>

Anyone got any idea if a Windows version of this process is possible/available? It looks very useful.

---

<div class="post-metadata">

**Author:** ![ryanjamurphy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/ryanjamurphy/32/334_2.png) [@ryanjamurphy](https://forum.obsidian.md/u/ryanjamurphy)\
**Post date:** [July 11, 2020, 2:26pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/5 "2020-07-11T14:26:59Z")

</div>

@AutonomyGaps Great idea. It probably actually isn’t that hard to do what you’re doing automatically within KM either, so that no manual intervention is needed… I will investigate.

@Jeffurry _Join us on the macOS side._ Keyboard Maestro is particularly accessible _and_ powerful, thanks to a few key design elements on the Mac. Still, try searching for macro software for whatever OS you’re using. There might be something! This macro isn’t that difficult to replicate, you just need software that copies the file names of selected files and adds the `- [[]]` text.

---

<div class="post-metadata">

**Author:** ![Jeffurry](https://forum.obsidian.md/user_avatar/forum.obsidian.md/jeffurry/32/207_2.png) [@Jeffurry](https://forum.obsidian.md/u/Jeffurry)\
**Post date:** [July 11, 2020, 7:17pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/6 "2020-07-11T19:17:26Z")

</div>

Macs are far too expensive for my present pocket, but almost all the ‘productivity’ things I look at on t’webz are heavily populated by Mac people. I do feel I am missing out.  
I am investigating AHK at the moment…

---

<div class="post-metadata">

**Author:** ![Stan](https://forum.obsidian.md/user_avatar/forum.obsidian.md/stan/32/919_2.png) [@Stan](https://forum.obsidian.md/u/Stan)\
**Post date:** [July 11, 2020, 7:40pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/7 "2020-07-11T19:40:39Z")

</div>

@ryanjamurphy  
Great tip!  
Could your KM macro be triggered by an x-callback-URL request to Keyboard Maestro?

---

<div class="post-metadata">

**Author:** ![ryanjamurphy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/ryanjamurphy/32/334_2.png) [@ryanjamurphy](https://forum.obsidian.md/u/ryanjamurphy)\
**Post date:** [July 12, 2020, 1:52pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/8 "2020-07-12T13:52:05Z")

</div>

Aye, if I understand your question correctly, that’s what the URL triggers are for! See the list at the top of the screenshot.

(It’s not strictly x-callback though. Let me know if you have a specific need for x-callback…?)

---

<div class="post-metadata">

**Author:** ![Stan](https://forum.obsidian.md/user_avatar/forum.obsidian.md/stan/32/919_2.png) [@Stan](https://forum.obsidian.md/u/Stan)\
**Post date:** [July 13, 2020, 1:19pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/9 "2020-07-13T13:19:59Z")

</div>

@ryanjamurphy  
I’m new to KM and I’ll explore the triggers in the list and see how it goes.  
Why are there 4 separate triggers?  
Thanks

---

<div class="post-metadata">

**Author:** ![ryanjamurphy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/ryanjamurphy/32/334_2.png) [@ryanjamurphy](https://forum.obsidian.md/u/ryanjamurphy)\
**Post date:** [July 13, 2020, 3:47pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/10 "2020-07-13T15:47:07Z")

</div>

KM generates four options for URL triggers by default. Not sure you can reduce it, actually, but you (a) don’t need to use URL triggers (there are a variety of other options) and (b) you only need to use one of them, whichever suits.

---

<div class="post-metadata">

**Author:** ![tristanbailey](https://forum.obsidian.md/user_avatar/forum.obsidian.md/tristanbailey/32/4657_2.png) [@tristanbailey](https://forum.obsidian.md/u/tristanbailey)\
**Post date:** [October 13, 2020, 5:11am UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/11 "2020-10-13T05:11:47Z")

</div>

If you can write bash or windows scripting as don’t mind missing the UI way this one works. You could look at the way I posted to do something similar with “espanso” it runs on few platforms

I wrote a bash script to list all files and make an index (for me though I just wanted the Zettelkasten ids but could make it like this too)

---

<div class="post-metadata">

**Author:** ![aroddick](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@aroddick](https://forum.obsidian.md/u/aroddick)\
**Post date:** [July 8, 2021, 5:40pm UTC](https://forum.obsidian.md/t/create-a-table-of-contents-from-selected-files-on-macos-using-keyboard-maestro/3008/12 "2021-07-08T17:40:17Z")

</div>

Just coming across this a year later, and is exactly what I was looking for. Cheers!
