Obsidian to Claude bash script
Recently I built a small bash script to take periodic notes from obsidian and copy them into my clip board so that I can paste them into Claude for processing.
Here is the script:
#!/bin/bash
# Create a temporary file
temp_file=$(mktemp)
# Concatenate all non-empty .md files in the current directory, adding titles and separators
for file in *.md; do
if [ -f "$file" ] && [ -s "$file" ] && ! [ -z "$(grep -v '^[[:space:]]*$' "$file")" ]; then
echo -e "\n====== $file ======\n" >> "$temp_file"
cat "$file" >> "$temp_file"
echo -e "\n" >> "$temp_file"
fi
done
# Function to check if running in WSL
is_wsl() {
if [ -f /proc/version ]; then
if grep -qi microsoft /proc/version; then
return 0
fi
fi
return 1
}
# Copy the concatenated content to clipboard
if is_wsl; then
# Running in WSL, use clip.exe
cat "$temp_file" | clip.exe
echo "Copied to Windows clipboard using clip.exe"
elif command -v xclip > /dev/null; then
xclip -selection clipboard < "$temp_file"
echo "Copied to clipboard using xclip"
elif command -v pbcopy > /dev/null; then
pbcopy < "$temp_file"
echo "Copied to clipboard using pbcopy"
elif command -v clip > /dev/null; then
clip < "$temp_file"
echo "Copied to clipboard using clip"
else
echo "Error: No suitable clipboard command found."
rm "$temp_file"
exit 1
fi
# Remove the temporary file
rm "$temp_file"
echo "All non-empty .md files have been concatenated with titles, and the result has been copied to the clipboard."
You simply just call the script and it will copy all of the notes from the current directory and paste them into your clipboard.
Then I pasted that into Claude to summarize with the following prompt:
you are a helpful assistant that takes a md file containing all the notes for a month and summarizes them into a single note.
How I used this was by moving periodic notes for each month into a folder, running the script, and then pasting the results into Claude for summarization. Then taking the summary and placing it into a new annual summary note.
e.g.
### January
**Major Projects and Research Areas**
- Project 1
- Project 2
- Project 3
### February
**Major Projects and Research Areas**
...
### March
**Major Projects and Research Areas**
...
I’m sure it could use some improvement, but it works well for my needs.
Read other posts