Obsidian to DayOne

Hi, I am looking for a plugin that helps me get certain entries in Obsidian safely tucked away in DayOne (my go to app for journaling).

I found a lot where data flows from DO to Obsidian but I want it the other way around. Is there anything like that?

2 Likes

Hi there,

I built a little script to do that for me. You need to install the Day One CLI module and update the paths as appropriate. As noted in the script, I don’t pull stuff right away, but rather let it slide 10 entries so that I can go back to fill in some details before it gets moved to Day One. Also adds a link to the original Obsidian entry so that you can jump back into Obsidian to leverage stuff like the graph view or internal navigation to other entries.

I run this on a daily cron job.

#!/bin/zsh

cd ~"/Library/Mobile Documents/iCloud~md~obsidian/Documents/Consulting/DailyNotes"
# get the number of entries so that the file list can be limited to all but the last 10 files so that I can go back and do updates on recent entries before getting committed to Day One
filecount=( $(ls | wc -l) )
(( filecount = $filecount - 10 ))

files=( $(ls | head -n $filecount) ) # get list of files in the directory

typeset -a imported=("${(f)"$(<imported.txt)"}") # import the previously imported notes list

declare -a toimport=()

# filter the previously imported files out of the list to be treated
for sourcefile in $files
do
	if [[ $sourcefile =~ '[0-9]{4}-[0-9]{2}-[0-9]{2}\.md$' ]]; then
		if [[ ${imported[(ie)$sourcefile]} -le ${#imported} ]];  then
			#echo "$sourcefile already imported"
		else
			echo "$sourcefile to be imported"
			toimport+=($sourcefile)
		fi
	fi
done

# Add the obsidian link to the original note and import into Day One
for file in $toimport
do
	parts=(${(@s:.:)file})
	filedate=$parts[1]
	filelink="[obsidian](obsidian://open?vault=Consulting&file=DailyNotes/$filedate)"
	sed -i '' -e '$a\' $file
	echo $'\n\n' >> $file
	echo $filelink >> $file
	
	cat $file | /usr/local/bin/dayone2 new -j "Work" -z CET -d $filedate
	echo $file >> imported.txt

done

2 Likes

Thank you very much! This seems to suit my needs just fine. I will experiment with it tonight to make sure I get it working properly.

1 Like

Thank you for sharing! I wonder if it is possible to only include dates from today and earlier. I have entries for some future dates also created in my daily notes and I would not like to transfer those to DayOne.

It should be doable by adding whatever filtering rules you need into the script once you have the $filelist variable. My rules are pretty simplistic and based on my workflow where I might go back and update some daily notes in the few days after I make them so I exclude the last 10 files (which is really not sophisticated evaluation of the actual dates).

Of course, this will involve some date math which is always fun.

1 Like