I'm trying to come up with a solution for "micro" posts which would be posts which wouldn't necessarily be long enough to warrant a title. I'm curious if it would be possible to run a command on the command line within my vault or setup a script of some sort that looked at the body of a note, ignored a codeblock at the top if there was one (typically a `yaml` block which held BearBlogs metaata for easy copy/pasting) and possibly also ignoring a markdown image syntax which may be the first line of a post, and extracted a certain amount of characters from the body to use as a title? Please let me know if I'm being clear on what I am trying to accomplish.
---
You're being quite clear! Let me restate it to confirm:
You want a script that, given a note file, generates a title by:
1. Skipping a leading fenced code block (e.g. ` ```yaml ... ``` `) if present
2. Skipping a leading markdown image line (e.g. ``) if present
3. Taking the first N characters of the remaining body content to use as the title
A few things to help me tailor this well:
---
Q: What language/environment do you prefer for the script? A: Bash/shell script
Q: How should the script be used? A: Run on a single file passed as an argument
Q: What should the script do with the extracted title? A: Copy it to clipboard
---
No relevant skill here — straightforward bash script. Here's what I'll build:
- Skips a leading ` ```yaml ... ``` ` fenced block
- Skips a leading markdown image line (``
- Extracts the first 60 characters of the remaining content (truncating cleanly at a word boundary)
- Copies to clipboard via `pbcopy` (macOS) with a fallback to `xclip`/`xsel` for Linux**Setup — one time:**
```bash
chmod +x note-title.sh
```
**Usage:**
```bash
./note-title.sh path/to/note.md # defaults to 60 chars
./note-title.sh path/to/note.md 80 # custom length
```
The title is copied to your clipboard and also printed to the terminal so you can see it.
**What it handles:**
- A leading ` ```yaml ... ``` ` (or any language) fenced block is skipped entirely
- A leading markdown image line (`` or `![alt][ref]`) is skipped
- Blank lines between those blocks and the real body are skipped
- The extract trims to a word boundary (no mid-word cuts) and appends `…` if truncated
- Clipboard: uses `pbcopy` on macOS, falls back to `xclip` or `xsel` on Linux
One thing worth noting: the script currently reads **all body lines** and joins them with spaces before trimming, so if your note's first paragraph spans multiple lines, they'll be treated as one continuous sentence — which is probably what you want for a title.
---
Oversight on my part. The script needs to also ignore Obsidian's baked in "YAML" properties at the top of the file, such as:
```
---
aliases:
tags:
publish:
created: 2026-03-19 22:13
modified: 2026-03-24 23:41
status:
title: Grandma, Shadow & Pixel Against the World
link: gma-shadow-pixel
---
```
---
Easy fix — that's a standard YAML front matter block, delimited by `---` at the top of the file. I'll add logic to skip it before the existing fenced code block check.Looks clean. The order of skipping is now:
1. `---` YAML front matter (Obsidian properties)
2. ` ```yaml ` fenced code block (your BearBlog metadata block)
3. Markdown image line
4. Blank lines
5. → first real body textOne subtle thing worth noting: the YAML front matter check only triggers if `---` is the very first line of the file (which is the spec-correct behavior). If there's any leading blank line before it, it won't be treated as front matter — but Obsidian doesn't do that, so you should be fine.
---
[[Run From Anywhere]]