Created
March 12, 2024 18:22
-
-
Save cwhittl/21869e95b26f5705f9409330c751e784 to your computer and use it in GitHub Desktop.
New Obsidian Convert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define the paths to the Supernote, Supernote Tool, and Obsidian directories | |
$dropBoxPath = "/Users/chris/Dropbox" | |
$obsidianVaultPath = "/Users/chris/Obsidian/WhitsNotesV6" | |
$superNotePath = "${dropBoxPath}/Supernote/Note" | |
$noteTakingAppPath = "${obsidianVaultPath}/_Inbox/" | |
$pdfPath = "${obsidianVaultPath}/zSupporting Files/Attachments/SuperNote/" | |
$superNoteToolPath = "/Library/Frameworks/Python.framework/Versions/3.12/bin/supernote-tool" | |
$returnLine = "`r`n" | |
# Delete the existing PDF and image directories if they exist | |
if (Test-Path $pdfPath) { | |
Remove-Item -Force -Recurse -Path $pdfPath | |
} | |
New-Item -ItemType Directory -Path $pdfPath | |
# Get a list of all of the .note files in the Supernote directory | |
$noteFiles = Get-ChildItem -Recurse -Path $superNotePath -Filter *.note | |
# Iterate over each .note file and convert it to a PDF and image file | |
foreach ($noteFile in $noteFiles) { | |
# Get the file ID from the .note file | |
$fileID = Get-Content -Path $noteFile.FullName -Raw | Select-String -Pattern "<FILE_ID:(.*?)>" | ForEach-Object { $_.Matches.Groups[1].Value } | |
# Get the file name and path without the extension | |
$noteFilePath = $noteFile.DirectoryName | |
$noteFileNameWithOutExt = $noteFile.BaseName | |
$notePathTags = $noteFilePath.Replace($dropBoxPath,"").Replace(" ", "").Replace("/","${returnLine} - ") | |
$noteFileNameTags = $noteFileNameWithOutExt.Replace(" ", "").Replace("_","${returnLine} - ") | |
$noteCreatedDate = $noteFile.CreationTime.ToString() | |
$noteTags = "${notePathTags}${returnLine} - ${noteFileNameTags}" | |
# Generate the paths to the PDF and image files | |
$pdfFileName = "${fileID}.pdf" | |
$pdfFile = Join-Path -Path $pdfPath -ChildPath "${pdfFileName}" | |
# Convert the .note file to a PDF file if it doesn't exist or is newer than the existing PDF file | |
if (! (Test-Path $pdfFile) -or ($noteFile.LastWriteTime -gt $pdfFile.LastWriteTime)) { | |
$noteFullPath = $noteFile.FullName | |
Write-Output "${superNoteToolPath} convert --policy=loose -t pdf -a ""$noteFullPath"" ""$pdfFile""" | |
Invoke-Expression "${superNoteToolPath} convert --policy=loose -t pdf -a ""$noteFullPath"" ""$pdfFile""" | |
} | |
# Get the path to the Markdown file | |
#$markdownPath = Join-Path -Path $noteTakingAppPath -ChildPath $noteFilePath.Substring($superNotePath.Length) | |
$markdownFile = Join-Path -Path $noteTakingAppPath -ChildPath "${noteFileNameWithOutExt}.md" | |
# Check if the Markdown file already contains a reference to the image file | |
#$existingMarkdownFile = Get-ChildItem -Path $obsidianVaultPath -Filter *.md -Recurse | Where-Object { Get-Content -Path $_.FullName -Raw | Select-String -Pattern "${fileID}.pdf" } | |
$existingMarkdownFile = Get-ChildItem "${obsidianVaultPath}\*.md" -recurse | Select-String -Pattern "${fileID}.pdf" | |
# If the Markdown file doesn't contain a reference to the image file, add it | |
if ($existingMarkdownFile.length -eq 0) { | |
New-Item -ItemType File -Path "$markdownFile" -Force | |
Add-Content -Path "$markdownFile" -Value "---${returnLine}tags:${returnLine}${noteTags}${returnLine}createddate: ${noteCreatedDate}${returnLine}participants: ${returnline}---${returnLine}" | |
Add-Content -Path "$markdownFile" -Value "- [ ] File Incoming SuperNote ${noteFileNameWithOutExt}" | |
Add-Content -Path "$markdownFile" -Value "#### *SuperNote Files Do Not Edit Below This Line*" | |
Add-Content -Path "$markdownFile" -Value "![[$pdfFileName]]" | |
} else { | |
Write-Output "Already Exists" | |
} | |
} | |
# SuperNote Can export |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment