Skip to content

Instantly share code, notes, and snippets.

@cwhittl
Created May 29, 2023 23:46
Show Gist options
  • Save cwhittl/9da069a4b9c7b915c910c091d720b7c0 to your computer and use it in GitHub Desktop.
Save cwhittl/9da069a4b9c7b915c910c091d720b7c0 to your computer and use it in GitHub Desktop.
Super note to Obsidian
#!/bin/bash
superNotePath="/Users/chriswhittle/Dropbox/Supernote/Note"
superNoteToolPath="/opt/homebrew/bin/supernote-tool"
noteTakingAppPath="/Users/chriswhittle/Library/Mobile Documents/iCloud~md~obsidian/Documents/WhitsNotes"
pdfPath="/Users/chriswhittle/Library/Mobile Documents/iCloud~md~obsidian/Documents/WhitsNotes/SuperNote/pdf"
imagePath="/Users/chriswhittle/Library/Mobile Documents/iCloud~md~obsidian/Documents/WhitsNotes/SuperNote/images"
if [[ -d $pdfPath ]]
then
echo "Deleting Old Pdfs"
rm -rf "${pdfPath}"
fi
mkdir -p "${pdfPath}"
#echo $imagePath
if [[ -d "${imagePath}" ]]
then
echo "Deleting Old Images"
rm -rf "${imagePath}"
fi
mkdir -p "${imagePath}"
find "${superNotePath}" -name "*.note" -print0 | while read -d $'\0' noteFile
do
fileTag=$(env LANG=C grep -Eoaw -m 1 '(<FILE_ID:)(.*?)(>)' "$noteFile")
fileID=${fileTag/<FILE_ID:/}
fileID=${fileID/>/}
#awk -F '/(<FILE_ID:)(.*?)(>)/' -f "$noteFile"
#echo "$noteFile -- $fileID"
noteFileName=$(basename "${noteFile}")
noteFilePath=$(dirname "${noteFile}")
noteFileNameWithOutExt="${noteFileName/.note/}"
#echo $noteFile
#echo $noteFilePath
#echo $noteFileName
#echo $noteFileNameWithOutExt
pdfFilePath="${noteFilePath/$superNotePath/$pdfPath}"
pdfFile="${pdfFilePath}/${noteFileNameWithOutExt}.pdf"
#echo $pdfFile
if [[ ! -f $pdfFile ]] || [[ $noteFile -nt $pdfFile ]]
then
mkdir -p "${pdfFilePath}"
fi
eval "$superNoteToolPath convert -t pdf -a \"$noteFile\" \"$pdfFile\""
imageFileWithoutExtension="${fileID}"
markdownPath="${noteFilePath/$superNotePath/$noteTakingAppPath/}"
markdownPath=${markdownPath/\/\//\/}
markdownFile="${markdownPath}/${noteFileNameWithOutExt}.md"
markdownFileHeader="> #### *SuperNote Files Do Not Edit Below This Line*"
imageFile="${imagePath}/${imageFileWithoutExtension}"
#echo $markdownPath
if [[ ! -f $imagePath ]] || [[ $noteFile -nt "${imageFile}_0.png" ]]
then
mkdir -p "${imagePath}"
fi
eval "$superNoteToolPath convert -a \"$noteFile\" \"${imageFile}.png\""
#echo "grep -rl --include="*.md" "${imageFileWithoutExtension}" "${noteTakingAppPath}""
existingMarkdownFile=$(grep -rl --include="*.md" "${imageFileWithoutExtension}" "${noteTakingAppPath}")
if [[ -f $existingMarkdownFile ]]
then
echo "found existing file - $existingMarkdownFile"
markdownFile=$existingMarkdownFile
else
if [[ ! -f $markdownFile ]]
then
#create file
echo "creating new file - $markdownFile"
mkdir -p "${markdownPath}"
markdownFileBody="> ![[${imageFileWithoutExtension}_0.png]]"
echo "\n\n\n${markdownFileHeader}\n${markdownFileBody}" > "${markdownFile}"
fi
fi
#echo $markdownFile
#SuperNote Can export multiple images so this is the way we make sure that we get all of those
for i in {1..100}
do
# echo "${imageFileWithoutExtension}_${i}"
# echo "$markdownFile"
if (! grep -q "${imageFileWithoutExtension}_${i}" "$markdownFile") && [[ -f "${imageFileWithoutExtension}_${i}.png" ]]; then
#append image
# echo "Append Image"
markdownFileBody="> ![[${imageFileWithoutExtension}_${i}.png]]"
echo "\n${markdownFileBody}" >> "${markdownFile}"
else
break;
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment