From 602e611152f6272f7ad8cc35c9f53226ab531d95 Mon Sep 17 00:00:00 2001 From: Matthew Turk Date: Mon, 12 Jun 2023 15:17:34 -0500 Subject: [PATCH 01/51] Add specifying parent folder for binary files --- src/Generator.ts | 7 +++++++ src/Setting.ts | 14 ++++++++++++++ src/main.ts | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/Generator.ts b/src/Generator.ts index cf97a77..e7614f6 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -34,6 +34,13 @@ export class MetaDataGenerator { if (!(file instanceof TFile)) { return false; } + if ( + !file.path.startsWith( + normalizePath(this.plugin.settings.binaryFilePath) + ) + ) { + return false; + } const matchedExtension = this.plugin.fileExtensionManager.getExtensionMatchedBest(file.name); diff --git a/src/Setting.ts b/src/Setting.ts index 545b096..31c7de8 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -118,6 +118,20 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName('Binary file parent folder') + .setDesc('Only this folder will be watched for new files') + .addSearch((component) => { + new FolderSuggest(this.app, component.inputEl); + component + .setPlaceholder('Example: folder1/folder2') + .setValue(this.plugin.settings.binaryFilePath) + .onChange((newFolder) => { + this.plugin.settings.binaryFilePath = newFolder; + this.plugin.saveSettings(); + }); + }); + let extensionToBeAdded: string; new Setting(containerEl) .setName('Extension to be watched') diff --git a/src/main.ts b/src/main.ts index 523eb7c..f67dfef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,7 @@ interface BinaryFileManagerSettings { autoDetection: boolean; extensions: string[]; folder: string; + binaryFilePath: string; filenameFormat: string; templatePath: string; useTemplater: boolean; @@ -36,6 +37,7 @@ const DEFAULT_SETTINGS: BinaryFileManagerSettings = { 'pdf', ], folder: '/', + binaryFilePath: '/', filenameFormat: 'INFO_{{NAME}}_{{EXTENSION:UP}}', templatePath: '', useTemplater: false, From d324275059488176f42f88e027c1c5b6bf7cc066 Mon Sep 17 00:00:00 2001 From: willjasen Date: Thu, 21 Dec 2023 20:25:12 -0500 Subject: [PATCH 02/51] change version and authors --- manifest.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index 53fc15c..c71ae63 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { "id": "obsidian-binary-file-manager-plugin", "name": "Binary File Manager", - "version": "0.3.0", + "version": "0.3.1", "minAppVersion": "0.12.0", "description": "Detects new binary files in the vault and create markdown files with metadata.", - "author": "qawatake", - "authorUrl": "https://github.com/qawatake/obsidian-binary-file-manager-plugin", + "author": "qawatake, matthewturk, willjasen", + "authorUrl": "https://github.com/willjasen/obsidian-binary-file-manager-plugin", "isDesktopOnly": false } From 9aea5f7b51e4857be8d8717c5ecb520dd15bfa0a Mon Sep 17 00:00:00 2001 From: willjasen Date: Thu, 21 Dec 2023 21:05:12 -0500 Subject: [PATCH 03/51] disabling mobile for now --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index c71ae63..6091c6f 100644 --- a/manifest.json +++ b/manifest.json @@ -6,5 +6,5 @@ "description": "Detects new binary files in the vault and create markdown files with metadata.", "author": "qawatake, matthewturk, willjasen", "authorUrl": "https://github.com/willjasen/obsidian-binary-file-manager-plugin", - "isDesktopOnly": false + "isDesktopOnly": true } From 687489a112abf4ad7a9ec9bd76277ddb4c571ff2 Mon Sep 17 00:00:00 2001 From: willjasen Date: Thu, 21 Dec 2023 22:48:26 -0500 Subject: [PATCH 04/51] compare folder path to parent folder in settings --- src/Generator.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index e7614f6..a943027 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -34,10 +34,14 @@ export class MetaDataGenerator { if (!(file instanceof TFile)) { return false; } + + let filePath = file.path.toString(); + let folderPath = filePath.substring(0,filePath.lastIndexOf("/")); + if ( - !file.path.startsWith( + !(folderPath === ( normalizePath(this.plugin.settings.binaryFilePath) - ) + )) ) { return false; } From d5d776f43a1c55247260981b5208b7985e015743 Mon Sep 17 00:00:00 2001 From: willjasen Date: Thu, 21 Dec 2023 23:38:05 -0500 Subject: [PATCH 05/51] update gui to show that subfolders are not watched --- src/Setting.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Setting.ts b/src/Setting.ts index 31c7de8..f0b42b4 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -119,8 +119,8 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); new Setting(containerEl) - .setName('Binary file parent folder') - .setDesc('Only this folder will be watched for new files') + .setName('Watched folder') + .setDesc('Only this folder will be watched for new files (subfolders will not be watched)') .addSearch((component) => { new FolderSuggest(this.app, component.inputEl); component From 4e3c502c6b8baabed86e9d5992a03afe407b8704 Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 01:06:16 -0500 Subject: [PATCH 06/51] binary file moves to attachment folder but links not updating --- src/Generator.ts | 40 ++++++++++++++++++++++++++++++++++++++-- src/Setting.ts | 14 ++++++++++++++ src/main.ts | 4 +++- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index a943027..482dbb6 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -64,8 +64,9 @@ export class MetaDataGenerator { this.generateMetaDataFileName(file) ); const metaDataFilePath = `${this.plugin.settings.folder}/${metaDataFileName}`; + const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; - await this.createMetaDataFile(metaDataFilePath, file as TFile); + await this.createMetaDataFile(metaDataFilePath, file as TFile, attachmentsFilePath); } private generateMetaDataFileName(file: TFile): string { @@ -92,7 +93,8 @@ export class MetaDataGenerator { private async createMetaDataFile( metaDataFilePath: string, - binaryFile: TFile + binaryFile: TFile, + attachmentsFilePath: string ): Promise { const templateContent = await this.fetchTemplateContent(); @@ -107,6 +109,16 @@ export class MetaDataGenerator { binaryFile.stat.ctime ) ); + + // move binary file into attachments folder + let binaryFileName = binaryFile.basename+"."+binaryFile.extension; + + try { + await this.app.fileManager.renameFile(binaryFile, (attachmentsFilePath+"/"+binaryFileName)); + } catch (err) { + alert(err); + } + } else { const targetFile = await this.app.vault.create( metaDataFilePath, @@ -193,4 +205,28 @@ export class MetaDataGenerator { return unlinkedBinaries; } + + findLinkedBinaries(): TFile[] { + const linkedBinaries: TFile[] = []; + const linkedPaths = new Set(); + + // collect all link destinations + Object.values(this.app.metadataCache.resolvedLinks).forEach((links) => { + Object.keys(links).forEach((dest) => { + linkedPaths.add(dest); + }); + }); + + // collect only unlinked binaries + this.app.vault.getFiles().forEach((file) => { + const isUnlinkedBinary = + !linkedPaths.has(file.path) && + this.plugin.fileExtensionManager.verify(file.path); + if (!isUnlinkedBinary) { + linkedBinaries.push(file); + } + }); + + return linkedBinaries; + } } diff --git a/src/Setting.ts b/src/Setting.ts index f0b42b4..45f14ea 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -132,6 +132,20 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName('Attachments folder') + .setDesc('Binary files will be moved here after metadata creation') + .addSearch((component) => { + new FolderSuggest(this.app, component.inputEl); + component + .setPlaceholder('Example: folder1/folder2') + .setValue(this.plugin.settings.attachmentsFilePath) + .onChange((newFolder) => { + this.plugin.settings.attachmentsFilePath = newFolder; + this.plugin.saveSettings(); + }); + }); + let extensionToBeAdded: string; new Setting(containerEl) .setName('Extension to be watched') diff --git a/src/main.ts b/src/main.ts index f67dfef..904c0a4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { Notice, Plugin, TAbstractFile, TFile } from 'obsidian'; +import { FileManager, Notice, Plugin, TAbstractFile, TFile } from 'obsidian'; import { Formatter } from 'Formatter'; import { BinaryFileManagerSettingTab } from 'Setting'; import { FileExtensionManager } from 'Extension'; @@ -10,6 +10,7 @@ interface BinaryFileManagerSettings { extensions: string[]; folder: string; binaryFilePath: string; + attachmentsFilePath: string; filenameFormat: string; templatePath: string; useTemplater: boolean; @@ -38,6 +39,7 @@ const DEFAULT_SETTINGS: BinaryFileManagerSettings = { ], folder: '/', binaryFilePath: '/', + attachmentsFilePath: '/', filenameFormat: 'INFO_{{NAME}}_{{EXTENSION:UP}}', templatePath: '', useTemplater: false, From 7f7a5cdbe3f8ea77ec5de72abb0460ea0cc01a6e Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 01:21:19 -0500 Subject: [PATCH 07/51] binary file moves and links are updated properly yay! --- src/Generator.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index 482dbb6..43c58ba 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -100,19 +100,18 @@ export class MetaDataGenerator { // process by Templater const templaterPlugin = await this.getTemplaterPlugin(); + const binaryFileName = binaryFile.basename+"."+binaryFile.extension; if (!(this.plugin.settings.useTemplater && templaterPlugin)) { this.app.vault.create( metaDataFilePath, this.plugin.formatter.format( templateContent, - binaryFile.path, + (attachmentsFilePath+"/"+binaryFileName), binaryFile.stat.ctime ) ); // move binary file into attachments folder - let binaryFileName = binaryFile.basename+"."+binaryFile.extension; - try { await this.app.fileManager.renameFile(binaryFile, (attachmentsFilePath+"/"+binaryFileName)); } catch (err) { From eee3fd51ec65c6722d3de29ba6a766a718cb866c Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 01:26:28 -0500 Subject: [PATCH 08/51] moving gui settings around --- src/Setting.ts | 56 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Setting.ts b/src/Setting.ts index 45f14ea..7d74ae0 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -39,6 +39,34 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName('Watched folder') + .setDesc('Only this folder will be watched for new files (subfolders will not be watched)') + .addSearch((component) => { + new FolderSuggest(this.app, component.inputEl); + component + .setPlaceholder('Example: folder1/folder2') + .setValue(this.plugin.settings.binaryFilePath) + .onChange((newFolder) => { + this.plugin.settings.binaryFilePath = newFolder; + this.plugin.saveSettings(); + }); + }); + + new Setting(containerEl) + .setName('Attachments folder') + .setDesc('Binary files will be moved here after metadata creation') + .addSearch((component) => { + new FolderSuggest(this.app, component.inputEl); + component + .setPlaceholder('Example: folder1/folder2') + .setValue(this.plugin.settings.attachmentsFilePath) + .onChange((newFolder) => { + this.plugin.settings.attachmentsFilePath = newFolder; + this.plugin.saveSettings(); + }); + }); + new Setting(containerEl) .setName('New file location') .setDesc('New metadata file will be placed here') @@ -118,34 +146,6 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); }); - new Setting(containerEl) - .setName('Watched folder') - .setDesc('Only this folder will be watched for new files (subfolders will not be watched)') - .addSearch((component) => { - new FolderSuggest(this.app, component.inputEl); - component - .setPlaceholder('Example: folder1/folder2') - .setValue(this.plugin.settings.binaryFilePath) - .onChange((newFolder) => { - this.plugin.settings.binaryFilePath = newFolder; - this.plugin.saveSettings(); - }); - }); - - new Setting(containerEl) - .setName('Attachments folder') - .setDesc('Binary files will be moved here after metadata creation') - .addSearch((component) => { - new FolderSuggest(this.app, component.inputEl); - component - .setPlaceholder('Example: folder1/folder2') - .setValue(this.plugin.settings.attachmentsFilePath) - .onChange((newFolder) => { - this.plugin.settings.attachmentsFilePath = newFolder; - this.plugin.saveSettings(); - }); - }); - let extensionToBeAdded: string; new Setting(containerEl) .setName('Extension to be watched') From 1e2ef15198248b553b3f168fd71bb25e06840385 Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 01:30:07 -0500 Subject: [PATCH 09/51] switch back to allow mobile --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 6091c6f..c71ae63 100644 --- a/manifest.json +++ b/manifest.json @@ -6,5 +6,5 @@ "description": "Detects new binary files in the vault and create markdown files with metadata.", "author": "qawatake, matthewturk, willjasen", "authorUrl": "https://github.com/willjasen/obsidian-binary-file-manager-plugin", - "isDesktopOnly": true + "isDesktopOnly": false } From ed82521c29436e17d6f835bcee5cd8f5b87aed4e Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 01:39:22 -0500 Subject: [PATCH 10/51] adding that binary file can be moved --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9583be5..b736357 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ ## Binary File Manager Plugin -This plugin detects new binary files in the vault and create markdown files with metadata. +This plugin detects new binary files in the vault and creates markdown files with metadata. The new binary file can then be moved into a different directory, like attachments. By using metadata files, you can take advantage of the rich functionality provied by Obsidian such as -- full text search, -- tags and aliases, +- full text search, +- tags and aliases, - internal links, and so on. For example, if you add tags to the metadata of an image file, then you can indirectly access the image file by tag-searching (and following an internal link in the metadata). From b09df2d93686af3a061ac0b4682ba9561a771d62 Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 01:42:04 -0500 Subject: [PATCH 11/51] refactoring move to path --- src/Generator.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index 43c58ba..5464111 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -101,19 +101,20 @@ export class MetaDataGenerator { // process by Templater const templaterPlugin = await this.getTemplaterPlugin(); const binaryFileName = binaryFile.basename+"."+binaryFile.extension; + const moveToFullFilePath = attachmentsFilePath+"/"+binaryFileName; if (!(this.plugin.settings.useTemplater && templaterPlugin)) { this.app.vault.create( metaDataFilePath, this.plugin.formatter.format( templateContent, - (attachmentsFilePath+"/"+binaryFileName), + moveToFullFilePath, binaryFile.stat.ctime ) ); // move binary file into attachments folder try { - await this.app.fileManager.renameFile(binaryFile, (attachmentsFilePath+"/"+binaryFileName)); + await this.app.fileManager.renameFile(binaryFile, moveToFullFilePath); } catch (err) { alert(err); } From e8dd09a5b4d012b56c131e0438a123e30b850097 Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 01:43:58 -0500 Subject: [PATCH 12/51] changing setting name --- src/Setting.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Setting.ts b/src/Setting.ts index 7d74ae0..a035ac7 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -68,7 +68,7 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); new Setting(containerEl) - .setName('New file location') + .setName('Metadata location') .setDesc('New metadata file will be placed here') .addSearch((component) => { new FolderSuggest(this.app, component.inputEl); From 97a1ff5be5109c0c17eac2925ef42c9cb7e645d7 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 22 Dec 2023 01:53:40 -0500 Subject: [PATCH 13/51] update header and add version button --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b736357..490a9f9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -## Binary File Manager Plugin +## Obsidian Binary File Manager + +![GitHub manifest version (path)](https://img.shields.io/github/manifest-json/v/willjasen/obsidian-binary-file-manager-plugin) This plugin detects new binary files in the vault and creates markdown files with metadata. The new binary file can then be moved into a different directory, like attachments. From 75286276a4837319c2b58a2cc36642cef961f080 Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 01:59:38 -0500 Subject: [PATCH 14/51] adding notice of moved file --- src/Generator.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Generator.ts b/src/Generator.ts index 5464111..9baadaf 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -115,6 +115,7 @@ export class MetaDataGenerator { // move binary file into attachments folder try { await this.app.fileManager.renameFile(binaryFile, moveToFullFilePath); + new Notice(`Binary file of ${binaryFileName} has been moved.`); } catch (err) { alert(err); } From 29dc15d18ee86a472e00c2e3d8fcbdbd536e0784 Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 02:30:55 -0500 Subject: [PATCH 15/51] created moveBinaryFile function --- src/Generator.ts | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index 9baadaf..22f932f 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -64,9 +64,9 @@ export class MetaDataGenerator { this.generateMetaDataFileName(file) ); const metaDataFilePath = `${this.plugin.settings.folder}/${metaDataFileName}`; - const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; - await this.createMetaDataFile(metaDataFilePath, file as TFile, attachmentsFilePath); + + await this.createMetaDataFile(metaDataFilePath, file as TFile); } private generateMetaDataFileName(file: TFile): string { @@ -91,32 +91,45 @@ export class MetaDataGenerator { } } + private async moveBinaryFile( + binaryFile: TFile + ): Promise { + // move binary file into attachments folder + const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; + const binaryFileName = binaryFile.basename+"."+binaryFile.extension; + const fullFilePath = attachmentsFilePath+"/"+binaryFileName; + try { + await this.app.fileManager.renameFile(binaryFile, fullFilePath); + new Notice(`Binary file of ${binaryFileName} has been moved.`); + } catch (err) { + alert(err); + } + } + private async createMetaDataFile( metaDataFilePath: string, - binaryFile: TFile, - attachmentsFilePath: string + binaryFile: TFile ): Promise { const templateContent = await this.fetchTemplateContent(); + const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; + const binaryFileName = binaryFile.basename+"."+binaryFile.extension; + const fullFilePath = attachmentsFilePath+"/"+binaryFileName; // process by Templater const templaterPlugin = await this.getTemplaterPlugin(); - const binaryFileName = binaryFile.basename+"."+binaryFile.extension; - const moveToFullFilePath = attachmentsFilePath+"/"+binaryFileName; if (!(this.plugin.settings.useTemplater && templaterPlugin)) { this.app.vault.create( metaDataFilePath, this.plugin.formatter.format( templateContent, - moveToFullFilePath, + fullFilePath, binaryFile.stat.ctime ) ); - // move binary file into attachments folder try { - await this.app.fileManager.renameFile(binaryFile, moveToFullFilePath); - new Notice(`Binary file of ${binaryFileName} has been moved.`); - } catch (err) { + await this.moveBinaryFile(binaryFile); + } catch(err) { alert(err); } From dde7df72f89c7e7716cae40f73822067ea242a49 Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 02:47:04 -0500 Subject: [PATCH 16/51] moved file will be renamed if one there already exists --- src/Generator.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index 22f932f..b1f1030 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -65,7 +65,6 @@ export class MetaDataGenerator { ); const metaDataFilePath = `${this.plugin.settings.folder}/${metaDataFileName}`; - await this.createMetaDataFile(metaDataFilePath, file as TFile); } @@ -91,12 +90,32 @@ export class MetaDataGenerator { } } + private uniquefyBinaryFileName(binaryFileName: string): string { + const binaryFilePath = normalizePath( + `${this.plugin.settings.folder}/${binaryFileName}` + ); + const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; + const attachmentFullFilePath = attachmentsFilePath+"/"+binaryFileName; + if (this.app.vault.getAbstractFileByPath(attachmentFullFilePath)) { + return `CONFLICT-${moment().format( + 'YYYY-MM-DD-hh-mm-ss' + )}-${binaryFileName}`; + } else { + return binaryFileName; + } + } + private async moveBinaryFile( binaryFile: TFile ): Promise { + + const binaryFileName = this.uniquefyBinaryFileName( + binaryFile.basename+"."+binaryFile.extension + ); + // move binary file into attachments folder const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; - const binaryFileName = binaryFile.basename+"."+binaryFile.extension; + //const binaryFileName = binaryFile.basename+"."+binaryFile.extension; const fullFilePath = attachmentsFilePath+"/"+binaryFileName; try { await this.app.fileManager.renameFile(binaryFile, fullFilePath); From 6b4e0a3077501212f77f2e95f71d4945090ff80b Mon Sep 17 00:00:00 2001 From: willjasen Date: Fri, 22 Dec 2023 02:48:04 -0500 Subject: [PATCH 17/51] update version to 0.4.0 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index c71ae63..2d402ee 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-binary-file-manager-plugin", "name": "Binary File Manager", - "version": "0.3.1", + "version": "0.4.0", "minAppVersion": "0.12.0", "description": "Detects new binary files in the vault and create markdown files with metadata.", "author": "qawatake, matthewturk, willjasen", From 8fab81304fea642359771e4291e81ddfb0b1f7bc Mon Sep 17 00:00:00 2001 From: willjasen Date: Mon, 1 Jan 2024 19:45:06 -0500 Subject: [PATCH 18/51] initial commit of build script --- build.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 build.sh diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..4583b4a --- /dev/null +++ b/build.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +SOURCE_DIR=/Users/willjasen/GitHub/obsidian-binary-file-manager-plugin; +PLUGIN_DIR=/Users/willjasen/Syncthing/Obsidian/willjasen/.obsidian/plugins/obsidian-binary-file-manager-plugin; + +# Go to the source directory and build it +cd $SOURCE_DIR; +npm i; +npm run build; + +# Copy built files into the plugin directory +cp $SOURCE_DIR/main.js $PLUGN_DIR/main.js +cp $SOURCE_DIR/manifest.js $PLUGN_DIR/manifest.js +cp $SOURCE_DIR/styles.css $PLUGN_DIR/styles.css From 907ad8969edf16af00f1271a0366439c16042cfa Mon Sep 17 00:00:00 2001 From: willjasen Date: Mon, 1 Jan 2024 19:45:31 -0500 Subject: [PATCH 19/51] enable execute permissions --- build.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 build.sh diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 From a94b1c8f306b86f980c67183794faeb2c5a759ee Mon Sep 17 00:00:00 2001 From: willjasen Date: Mon, 1 Jan 2024 19:52:24 -0500 Subject: [PATCH 20/51] fixing variable name --- build.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index 4583b4a..ae477b5 100755 --- a/build.sh +++ b/build.sh @@ -1,14 +1,14 @@ #!/bin/sh -SOURCE_DIR=/Users/willjasen/GitHub/obsidian-binary-file-manager-plugin; -PLUGIN_DIR=/Users/willjasen/Syncthing/Obsidian/willjasen/.obsidian/plugins/obsidian-binary-file-manager-plugin; +SOURCE_DIR="/Users/willjasen/GitHub/obsidian-binary-file-manager-plugin"; +PLUGIN_DIR="/Users/willjasen/Syncthing/Obsidian/willjasen/.obsidian/plugins/obsidian-binary-file-manager-plugin"; # Go to the source directory and build it -cd $SOURCE_DIR; +cd "$SOURCE_DIR"; npm i; npm run build; # Copy built files into the plugin directory -cp $SOURCE_DIR/main.js $PLUGN_DIR/main.js -cp $SOURCE_DIR/manifest.js $PLUGN_DIR/manifest.js -cp $SOURCE_DIR/styles.css $PLUGN_DIR/styles.css +cp "$SOURCE_DIR/main.js" "$PLUGIN_DIR/main.js"; +cp $SOURCE_DIR/manifest.json $PLUGIN_DIR/manifest.json +cp $SOURCE_DIR/styles.css $PLUGIN_DIR/styles.css From f628505dbb6651e6021de52039fcc7f4f300a6f5 Mon Sep 17 00:00:00 2001 From: willjasen Date: Mon, 1 Jan 2024 19:53:26 -0500 Subject: [PATCH 21/51] standardizing cp commands --- build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index ae477b5..1d7f8b4 100755 --- a/build.sh +++ b/build.sh @@ -9,6 +9,6 @@ npm i; npm run build; # Copy built files into the plugin directory -cp "$SOURCE_DIR/main.js" "$PLUGIN_DIR/main.js"; -cp $SOURCE_DIR/manifest.json $PLUGIN_DIR/manifest.json -cp $SOURCE_DIR/styles.css $PLUGIN_DIR/styles.css +cp $SOURCE_DIR/main.js $PLUGIN_DIR/main.js; +cp $SOURCE_DIR/manifest.json $PLUGIN_DIR/manifest.json; +cp $SOURCE_DIR/styles.css $PLUGIN_DIR/styles.css; From 2dee737bc4ed508be11646a3eab92d3c40f2b923 Mon Sep 17 00:00:00 2001 From: willjasen Date: Mon, 1 Jan 2024 20:01:09 -0500 Subject: [PATCH 22/51] switched to array and for loop --- build.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index 1d7f8b4..a83c06a 100755 --- a/build.sh +++ b/build.sh @@ -1,14 +1,17 @@ #!/bin/sh +# variables SOURCE_DIR="/Users/willjasen/GitHub/obsidian-binary-file-manager-plugin"; PLUGIN_DIR="/Users/willjasen/Syncthing/Obsidian/willjasen/.obsidian/plugins/obsidian-binary-file-manager-plugin"; +FILES=( "main.js" "manifest.json" "styles.css" ); # Go to the source directory and build it -cd "$SOURCE_DIR"; -npm i; -npm run build; +cd $SOURCE_DIR; +npm i; npm run build; # Copy built files into the plugin directory -cp $SOURCE_DIR/main.js $PLUGIN_DIR/main.js; -cp $SOURCE_DIR/manifest.json $PLUGIN_DIR/manifest.json; -cp $SOURCE_DIR/styles.css $PLUGIN_DIR/styles.css; +for file in "${FILES[@]}" +do + echo "Copying file: $file"; + cp $SOURCE_DIR/$file $PLUGIN_DIR/$file; +done From 0819de55acb686d9a6ea54e36291c54817d21584 Mon Sep 17 00:00:00 2001 From: willjasen Date: Mon, 1 Jan 2024 20:03:05 -0500 Subject: [PATCH 23/51] comments --- build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.sh b/build.sh index a83c06a..b3ad390 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,8 @@ #!/bin/sh +# This script builds the plugin and copies the output files into the associated plugin directory +# After the script is run, this plugin in Obisidian should disabled/enabled to refresh it + # variables SOURCE_DIR="/Users/willjasen/GitHub/obsidian-binary-file-manager-plugin"; PLUGIN_DIR="/Users/willjasen/Syncthing/Obsidian/willjasen/.obsidian/plugins/obsidian-binary-file-manager-plugin"; From 4ac848b2117539c0fc0dc8aa825d56dfcc024eb0 Mon Sep 17 00:00:00 2001 From: willjasen Date: Mon, 12 Feb 2024 14:21:59 -0500 Subject: [PATCH 24/51] changing plugin directory --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index b3ad390..9f7bc68 100755 --- a/build.sh +++ b/build.sh @@ -5,7 +5,7 @@ # variables SOURCE_DIR="/Users/willjasen/GitHub/obsidian-binary-file-manager-plugin"; -PLUGIN_DIR="/Users/willjasen/Syncthing/Obsidian/willjasen/.obsidian/plugins/obsidian-binary-file-manager-plugin"; +PLUGIN_DIR="/Users/willjasen/Obsidian/willjasen/.obsidian/plugins/obsidian-binary-file-manager-plugin"; FILES=( "main.js" "manifest.json" "styles.css" ); # Go to the source directory and build it From 26b1a1ef2e695740e2cfb74ca0abdac8ea39a0e9 Mon Sep 17 00:00:00 2001 From: willjasen Date: Mon, 12 Feb 2024 14:25:00 -0500 Subject: [PATCH 25/51] create the plugin directory if needed --- build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.sh b/build.sh index 9f7bc68..e1f7501 100755 --- a/build.sh +++ b/build.sh @@ -8,6 +8,9 @@ SOURCE_DIR="/Users/willjasen/GitHub/obsidian-binary-file-manager-plugin"; PLUGIN_DIR="/Users/willjasen/Obsidian/willjasen/.obsidian/plugins/obsidian-binary-file-manager-plugin"; FILES=( "main.js" "manifest.json" "styles.css" ); +# Create the directory if needed +[ -d $PLUGIN_DIR ] || mkdir $PLUGIN_DIR + # Go to the source directory and build it cd $SOURCE_DIR; npm i; npm run build; From 6491a3ac30261cdf70331678b3136c7d9af49ce8 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 2 Apr 2024 02:04:47 -0400 Subject: [PATCH 26/51] change generated note format --- src/Generator.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Generator.ts b/src/Generator.ts index b1f1030..30c09c7 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -12,10 +12,15 @@ import { UncoveredApp } from 'Uncover'; import { retry } from 'Util'; const TEMPLATER_PLUGIN_NAME = 'templater-obsidian'; -const DEFAULT_TEMPLATE_CONTENT = `![[{{PATH}}]] +const DEFAULT_TEMPLATE_CONTENT = ` +--- +tags: + - scanned-in +--- LINK: [[{{PATH}}]] CREATED At: {{CDATE:YYYY-MM-DD}} FILE TYPE: {{EXTENSION:UP}} +![[{{PATH}}]] `; const RETRY_NUMBER = 1000; From 8cf406ef72c7b4b3e7de459f2f59567095e2fd39 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 2 Apr 2024 02:11:38 -0400 Subject: [PATCH 27/51] generate tags property properly --- src/Generator.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index 30c09c7..cfd68b4 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -12,13 +12,12 @@ import { UncoveredApp } from 'Uncover'; import { retry } from 'Util'; const TEMPLATER_PLUGIN_NAME = 'templater-obsidian'; -const DEFAULT_TEMPLATE_CONTENT = ` ---- +const DEFAULT_TEMPLATE_CONTENT = `--- tags: - scanned-in --- LINK: [[{{PATH}}]] -CREATED At: {{CDATE:YYYY-MM-DD}} +CREATED AT: {{CDATE:YYYY-MM-DD}} FILE TYPE: {{EXTENSION:UP}} ![[{{PATH}}]] `; From 63f3b204c38e02575dc629baf2fbf47b844dc8d8 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 2 Apr 2024 03:07:17 -0400 Subject: [PATCH 28/51] tags are being added (but not fully working) --- src/Generator.ts | 18 +++++++++++++++--- src/Setting.ts | 35 +++++++++++++++++++++++++++++++++++ src/main.ts | 2 ++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index cfd68b4..9680b0b 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -12,9 +12,19 @@ import { UncoveredApp } from 'Uncover'; import { retry } from 'Util'; const TEMPLATER_PLUGIN_NAME = 'templater-obsidian'; -const DEFAULT_TEMPLATE_CONTENT = `--- -tags: - - scanned-in + +const TEMPLATE_PART_1 = +`--- +tags:`; + +let TEMPLATE_PART_2: string[] = ''; +this.plugin.settings.tags.forEach(function tag) { + `${TEMPLATE_PART_2} + - ${tag}`; +}); + +const TEMPLATE_PART_3 = +` --- LINK: [[{{PATH}}]] CREATED AT: {{CDATE:YYYY-MM-DD}} @@ -22,6 +32,8 @@ FILE TYPE: {{EXTENSION:UP}} ![[{{PATH}}]] `; +const DEFAULT_TEMPLATE_CONTENT = `${TEMPLATE_PART_1}${TEMPLATE_PART_2}${TEMPLATE_PART_3}`; + const RETRY_NUMBER = 1000; const TIMEOUT_MILLISECOND = 1000; diff --git a/src/Setting.ts b/src/Setting.ts index a035ac7..e4ca408 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -122,6 +122,41 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); }); + let tagToBeAdded: string; + new Setting(containerEl) + .setName('Tags to add') + .addText((text) => + text.setPlaceholder('Example: scan').onChange((value) => { + tagToBeAdded = value.trim().replace(/^\./, ''); + }) + ) + .addButton((cb) => { + cb.setButtonText('Add').onClick(async () => { + if ( + this.plugin.settings.tags.has(tagToBeAdded) + ) { + new Notice( + `${tagToBeAdded} is already registered` + ); + return; + } + this.plugin.settings.tags.push(tagToBeAdded); + await this.plugin.saveSettings(); + this.display(); + }); + }); + + this.plugin.settings.tags.forEach((tag) => { + new Setting(containerEl).setName(tag).addExtraButton((cb) => { + cb.setIcon('cross').onClick(async () => { + let index = this.plugin.settings.tags.indexOf(tag); + let removedElementsArray = this.plugin.settings.tags.splice(index, 1); + await this.plugin.saveSettings(); + this.display(); + }); + }); + }); + new Setting(containerEl) .setName('Template file location') .addSearch((component) => { diff --git a/src/main.ts b/src/main.ts index 904c0a4..d654fa3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,6 +14,7 @@ interface BinaryFileManagerSettings { filenameFormat: string; templatePath: string; useTemplater: boolean; + tags: string[]; } const DEFAULT_SETTINGS: BinaryFileManagerSettings = { @@ -43,6 +44,7 @@ const DEFAULT_SETTINGS: BinaryFileManagerSettings = { filenameFormat: 'INFO_{{NAME}}_{{EXTENSION:UP}}', templatePath: '', useTemplater: false, + tags: [], }; export default class BinaryFileManagerPlugin extends Plugin { From 7017fdaaaaf1e77e69c40c96f1005407b35748d6 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 20 Aug 2024 17:15:49 -0400 Subject: [PATCH 29/51] removing tags settings in favor of templater --- src/Generator.ts | 22 +--------------------- src/Setting.ts | 24 ------------------------ src/main.ts | 4 +--- 3 files changed, 2 insertions(+), 48 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index 9680b0b..8dc9414 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -12,27 +12,7 @@ import { UncoveredApp } from 'Uncover'; import { retry } from 'Util'; const TEMPLATER_PLUGIN_NAME = 'templater-obsidian'; - -const TEMPLATE_PART_1 = -`--- -tags:`; - -let TEMPLATE_PART_2: string[] = ''; -this.plugin.settings.tags.forEach(function tag) { - `${TEMPLATE_PART_2} - - ${tag}`; -}); - -const TEMPLATE_PART_3 = -` ---- -LINK: [[{{PATH}}]] -CREATED AT: {{CDATE:YYYY-MM-DD}} -FILE TYPE: {{EXTENSION:UP}} -![[{{PATH}}]] -`; - -const DEFAULT_TEMPLATE_CONTENT = `${TEMPLATE_PART_1}${TEMPLATE_PART_2}${TEMPLATE_PART_3}`; +const DEFAULT_TEMPLATE_CONTENT = ``; const RETRY_NUMBER = 1000; const TIMEOUT_MILLISECOND = 1000; diff --git a/src/Setting.ts b/src/Setting.ts index e4ca408..71f1e94 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -122,30 +122,6 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); }); - let tagToBeAdded: string; - new Setting(containerEl) - .setName('Tags to add') - .addText((text) => - text.setPlaceholder('Example: scan').onChange((value) => { - tagToBeAdded = value.trim().replace(/^\./, ''); - }) - ) - .addButton((cb) => { - cb.setButtonText('Add').onClick(async () => { - if ( - this.plugin.settings.tags.has(tagToBeAdded) - ) { - new Notice( - `${tagToBeAdded} is already registered` - ); - return; - } - this.plugin.settings.tags.push(tagToBeAdded); - await this.plugin.saveSettings(); - this.display(); - }); - }); - this.plugin.settings.tags.forEach((tag) => { new Setting(containerEl).setName(tag).addExtraButton((cb) => { cb.setIcon('cross').onClick(async () => { diff --git a/src/main.ts b/src/main.ts index d654fa3..e97aa1b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,7 +14,6 @@ interface BinaryFileManagerSettings { filenameFormat: string; templatePath: string; useTemplater: boolean; - tags: string[]; } const DEFAULT_SETTINGS: BinaryFileManagerSettings = { @@ -43,8 +42,7 @@ const DEFAULT_SETTINGS: BinaryFileManagerSettings = { attachmentsFilePath: '/', filenameFormat: 'INFO_{{NAME}}_{{EXTENSION:UP}}', templatePath: '', - useTemplater: false, - tags: [], + useTemplater: false }; export default class BinaryFileManagerPlugin extends Plugin { From f9f30ab3c8d6d694ca975a0a83efb6e85c2e9404 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 20 Aug 2024 17:17:14 -0400 Subject: [PATCH 30/51] add some verbose --- build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index e1f7501..b73733a 100755 --- a/build.sh +++ b/build.sh @@ -9,7 +9,7 @@ PLUGIN_DIR="/Users/willjasen/Obsidian/willjasen/.obsidian/plugins/obsidian-binar FILES=( "main.js" "manifest.json" "styles.css" ); # Create the directory if needed -[ -d $PLUGIN_DIR ] || mkdir $PLUGIN_DIR +[ -d $PLUGIN_DIR ] || echo "Creating plugin directory at $PLUGIN_DIR"; mkdir $PLUGIN_DIR; # Go to the source directory and build it cd $SOURCE_DIR; @@ -21,3 +21,4 @@ do echo "Copying file: $file"; cp $SOURCE_DIR/$file $PLUGIN_DIR/$file; done +echo "All files copied!"; \ No newline at end of file From d30d7a7dc1818ebe3e82ad0456823e2dd2609a85 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 20 Aug 2024 17:21:58 -0400 Subject: [PATCH 31/51] output where file is copied to --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index b73733a..dbcac4d 100755 --- a/build.sh +++ b/build.sh @@ -18,7 +18,7 @@ npm i; npm run build; # Copy built files into the plugin directory for file in "${FILES[@]}" do - echo "Copying file: $file"; + echo "Copying file: $file --> $PLUGIN_DIR/$file"; cp $SOURCE_DIR/$file $PLUGIN_DIR/$file; done echo "All files copied!"; \ No newline at end of file From 723fc708e6aae35f255da157aa3b2ce512e82f8a Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 20 Aug 2024 17:23:40 -0400 Subject: [PATCH 32/51] updated npm packages --- package.json | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 4f72e4f..cdc6cfb 100644 --- a/package.json +++ b/package.json @@ -17,21 +17,21 @@ "author": "qawatake", "license": "MIT", "devDependencies": { - "@types/node": "^17.0.5", - "@typescript-eslint/eslint-plugin": "^5.8.1", - "@typescript-eslint/parser": "^5.8.1", - "builtin-modules": "^3.2.0", - "esbuild": "~0.13.12", - "eslint": "^8.5.0", - "eslint-config-prettier": "^8.3.0", - "eslint-plugin-react": "^7.28.0", + "@types/node": "^22.4.1", + "@typescript-eslint/eslint-plugin": "^8.2.0", + "@typescript-eslint/parser": "^8.2.0", + "builtin-modules": "^4.0.0", + "esbuild": "~0.23.1", + "eslint": "^9.9.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-react": "^7.35.0", "npm-run-all": "^4.1.5", - "obsidian": "^0.13.11", - "prettier": "^2.5.1", - "tslib": "^2.3.1", - "typescript": "^4.5.4" + "obsidian": "^1.6.6", + "prettier": "^3.3.3", + "tslib": "^2.6.3", + "typescript": "^5.5.4" }, "dependencies": { - "@popperjs/core": "^2.11.0" + "@popperjs/core": "^2.11.8" } } From 1cd18fda74171f57cfff67507966038f20d4482e Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 20 Aug 2024 17:44:24 -0400 Subject: [PATCH 33/51] generator working with templater --- src/Generator.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index 8dc9414..a78eb26 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -105,14 +105,14 @@ export class MetaDataGenerator { binaryFile: TFile ): Promise { + const binaryFileName = this.uniquefyBinaryFileName( binaryFile.basename+"."+binaryFile.extension ); - - // move binary file into attachments folder const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; - //const binaryFileName = binaryFile.basename+"."+binaryFile.extension; const fullFilePath = attachmentsFilePath+"/"+binaryFileName; + + // move binary file into the attachments folder try { await this.app.fileManager.renameFile(binaryFile, fullFilePath); new Notice(`Binary file of ${binaryFileName} has been moved.`); @@ -161,14 +161,19 @@ export class MetaDataGenerator { { target_file: targetFile, run_mode: 4 }, this.plugin.formatter.format( templateContent, - binaryFile.path, + fullFilePath, binaryFile.stat.ctime ) ); this.app.vault.modify(targetFile, content); + try { + await this.moveBinaryFile(binaryFile); + } catch(err) { + alert(err); + } } catch (err) { new Notice( - 'ERROR in Binary File Manager Plugin: failed to connect to Templater. Your Templater version may not be supported' + 'ERROR in Binary File Manager Plugin: failed to connect to Templater. Your Templater version may not be supported.' ); console.log(err); } From d0896fcdc2140724900e5995935afde67d9e37ee Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 20 Aug 2024 18:19:20 -0400 Subject: [PATCH 34/51] make npm silent --- build.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index dbcac4d..545f0a3 100755 --- a/build.sh +++ b/build.sh @@ -9,11 +9,15 @@ PLUGIN_DIR="/Users/willjasen/Obsidian/willjasen/.obsidian/plugins/obsidian-binar FILES=( "main.js" "manifest.json" "styles.css" ); # Create the directory if needed -[ -d $PLUGIN_DIR ] || echo "Creating plugin directory at $PLUGIN_DIR"; mkdir $PLUGIN_DIR; +if [ -d $PLUGIN_DIR ]; then + echo "Plugin directory already exists."; +else + echo "Creating plugin directory at $PLUGIN_DIR"; mkdir $PLUGIN_DIR; +fi -# Go to the source directory and build it +# Go to the source directory and build this plugin cd $SOURCE_DIR; -npm i; npm run build; +npm i --silent; npm run build > /dev/null 2>&1; # Copy built files into the plugin directory for file in "${FILES[@]}" From 1ce1d6243498bcb1ef45a0cbc4fc90bb567c56ef Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 20 Aug 2024 18:22:33 -0400 Subject: [PATCH 35/51] fix the path --- src/Generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generator.ts b/src/Generator.ts index a78eb26..aa95515 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -161,7 +161,7 @@ export class MetaDataGenerator { { target_file: targetFile, run_mode: 4 }, this.plugin.formatter.format( templateContent, - fullFilePath, + binaryFile.path, binaryFile.stat.ctime ) ); From ef604f92f1286bc40b33650371476eb8a888d1f0 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 20 Aug 2024 18:33:16 -0400 Subject: [PATCH 36/51] adding a sleep due to conflicts with another plugin --- src/Generator.ts | 5 ++++- src/Util.ts | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Generator.ts b/src/Generator.ts index aa95515..8120695 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -9,7 +9,7 @@ import { Plugin, } from 'obsidian'; import { UncoveredApp } from 'Uncover'; -import { retry } from 'Util'; +import { retry, sleep } from 'Util'; const TEMPLATER_PLUGIN_NAME = 'templater-obsidian'; const DEFAULT_TEMPLATE_CONTENT = ``; @@ -125,6 +125,9 @@ export class MetaDataGenerator { metaDataFilePath: string, binaryFile: TFile ): Promise { + + await sleep(5000); + const templateContent = await this.fetchTemplateContent(); const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; const binaryFileName = binaryFile.basename+"."+binaryFile.extension; diff --git a/src/Util.ts b/src/Util.ts index 0d18db9..a10fc90 100644 --- a/src/Util.ts +++ b/src/Util.ts @@ -33,6 +33,10 @@ async function delay(milliSecond: number): Promise { return undefined; } +export async function sleep(ms: number): Promise { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + const INVALID_CHARS_IN_FILE_NAME = new Set([ '\\', '/', From a2ac8f9312c17a94a53fec6d634a83f50daefdb0 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 20 Aug 2024 20:00:27 -0400 Subject: [PATCH 37/51] refactoring moving the file --- src/Generator.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index 8120695..440c04a 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -117,6 +117,7 @@ export class MetaDataGenerator { await this.app.fileManager.renameFile(binaryFile, fullFilePath); new Notice(`Binary file of ${binaryFileName} has been moved.`); } catch (err) { + new Notice(`Problem moving the binary file of ${binaryFileName} into the attachments folder.`); alert(err); } } @@ -126,13 +127,19 @@ export class MetaDataGenerator { binaryFile: TFile ): Promise { - await sleep(5000); + // await sleep(1000); const templateContent = await this.fetchTemplateContent(); const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; const binaryFileName = binaryFile.basename+"."+binaryFile.extension; const fullFilePath = attachmentsFilePath+"/"+binaryFileName; + try { + await this.moveBinaryFile(binaryFile); + } catch(err) { + alert(err); + } + // process by Templater const templaterPlugin = await this.getTemplaterPlugin(); if (!(this.plugin.settings.useTemplater && templaterPlugin)) { @@ -145,12 +152,6 @@ export class MetaDataGenerator { ) ); - try { - await this.moveBinaryFile(binaryFile); - } catch(err) { - alert(err); - } - } else { const targetFile = await this.app.vault.create( metaDataFilePath, @@ -169,11 +170,7 @@ export class MetaDataGenerator { ) ); this.app.vault.modify(targetFile, content); - try { - await this.moveBinaryFile(binaryFile); - } catch(err) { - alert(err); - } + } catch (err) { new Notice( 'ERROR in Binary File Manager Plugin: failed to connect to Templater. Your Templater version may not be supported.' From 70fd50891aaf0727fa895cd83e487790e75416bf Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 20 Aug 2024 20:23:13 -0400 Subject: [PATCH 38/51] bump the version to 0.4.2 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 2d402ee..6998df6 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-binary-file-manager-plugin", "name": "Binary File Manager", - "version": "0.4.0", + "version": "0.4.2", "minAppVersion": "0.12.0", "description": "Detects new binary files in the vault and create markdown files with metadata.", "author": "qawatake, matthewturk, willjasen", From c84fa2f9507b6480de98d4facbe6c19d61a66b61 Mon Sep 17 00:00:00 2001 From: willjasen Date: Wed, 21 Aug 2024 14:43:54 -0400 Subject: [PATCH 39/51] change comment --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 545f0a3..c64028e 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/bin/sh # This script builds the plugin and copies the output files into the associated plugin directory -# After the script is run, this plugin in Obisidian should disabled/enabled to refresh it +# After this build script is run, this plugin in Obisidian should disabled/enabled to refresh it # variables SOURCE_DIR="/Users/willjasen/GitHub/obsidian-binary-file-manager-plugin"; From 48badecc9c97796bb507dbd796d8b929581fed8c Mon Sep 17 00:00:00 2001 From: willjasen Date: Wed, 21 Aug 2024 14:49:41 -0400 Subject: [PATCH 40/51] fix typo --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 6998df6..a6b4b4d 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "Binary File Manager", "version": "0.4.2", "minAppVersion": "0.12.0", - "description": "Detects new binary files in the vault and create markdown files with metadata.", + "description": "Detects new binary files in the vault and creates markdown files with metadata.", "author": "qawatake, matthewturk, willjasen", "authorUrl": "https://github.com/willjasen/obsidian-binary-file-manager-plugin", "isDesktopOnly": false From a0cbb84aa8def1c9176b3972a7fe92be1e67cca5 Mon Sep 17 00:00:00 2001 From: willjasen Date: Wed, 21 Aug 2024 15:46:25 -0400 Subject: [PATCH 41/51] remove the tags setting --- src/Setting.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Setting.ts b/src/Setting.ts index 71f1e94..a035ac7 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -122,17 +122,6 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); }); - this.plugin.settings.tags.forEach((tag) => { - new Setting(containerEl).setName(tag).addExtraButton((cb) => { - cb.setIcon('cross').onClick(async () => { - let index = this.plugin.settings.tags.indexOf(tag); - let removedElementsArray = this.plugin.settings.tags.splice(index, 1); - await this.plugin.saveSettings(); - this.display(); - }); - }); - }); - new Setting(containerEl) .setName('Template file location') .addSearch((component) => { From 4a4ba8162f138006e108f6f7bd177c237626b559 Mon Sep 17 00:00:00 2001 From: willjasen Date: Wed, 21 Aug 2024 15:51:52 -0400 Subject: [PATCH 42/51] hide the template file location setting if templater not used --- src/Setting.ts | 51 +++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/Setting.ts b/src/Setting.ts index a035ac7..442c206 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -122,29 +122,38 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); }); + // Create the "Use Templater" toggle setting new Setting(containerEl) - .setName('Template file location') - .addSearch((component) => { - new FileSuggest(this.app, component.inputEl); - component - .setPlaceholder('Example: folder1/note') - .setValue(this.plugin.settings.templatePath) - .onChange((newTemplateFile) => { - this.plugin.settings.templatePath = newTemplateFile; - this.plugin.saveSettings(); - }); - }); + .setName('Use Templater') + .addToggle(async (component) => { + component + .setValue(this.plugin.settings.useTemplater) + .onChange((value) => { + this.plugin.settings.useTemplater = value; + this.plugin.saveSettings(); + + // Show or hide the Template file location setting based on the toggle value + templateSetting.settingEl.style.display = value ? 'block' : 'none'; + }); + }); + + // Create the "Template file location" search setting and initially hide or show it + const templateSetting = new Setting(containerEl) + .setName('Template file location') + .addSearch((component) => { + new FileSuggest(this.app, component.inputEl); + component + .setPlaceholder('Example: folder1/note') + .setValue(this.plugin.settings.templatePath) + .onChange((newTemplateFile) => { + this.plugin.settings.templatePath = newTemplateFile; + this.plugin.saveSettings(); + }); + }); + + // Set the initial visibility of the "Template file location" setting + templateSetting.settingEl.style.display = this.plugin.settings.useTemplater ? 'block' : 'none'; - new Setting(containerEl) - .setName('Use Templater') - .addToggle(async (component) => { - component - .setValue(this.plugin.settings.useTemplater) - .onChange((value) => { - this.plugin.settings.useTemplater = value; - this.plugin.saveSettings(); - }); - }); let extensionToBeAdded: string; new Setting(containerEl) From 982cafc6cf31e8504a359bccafb630c5f4a0e318 Mon Sep 17 00:00:00 2001 From: willjasen Date: Wed, 21 Aug 2024 15:52:15 -0400 Subject: [PATCH 43/51] bump version to 0.4.3 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index a6b4b4d..66e4263 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-binary-file-manager-plugin", "name": "Binary File Manager", - "version": "0.4.2", + "version": "0.4.3", "minAppVersion": "0.12.0", "description": "Detects new binary files in the vault and creates markdown files with metadata.", "author": "qawatake, matthewturk, willjasen", From 18ce6e6ce204f5cdbf7b391c72ce92a4e44bfb78 Mon Sep 17 00:00:00 2001 From: willjasen Date: Sun, 23 Nov 2025 15:26:17 -0500 Subject: [PATCH 44/51] fix "Invalid option in build() call: "watch" --- esbuild.config.mjs | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/esbuild.config.mjs b/esbuild.config.mjs index d992da2..13a9c09 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -10,20 +10,29 @@ if you want to view the source, please visit the github repository of this plugi const prod = process.argv[2] === 'production'; -esbuild - .build({ - banner: { - js: banner, - }, - entryPoints: ['src/main.ts'], - bundle: true, - external: ['obsidian', 'electron', ...builtins], - format: 'cjs', - watch: !prod, - target: 'es2016', - logLevel: 'info', - sourcemap: prod ? false : 'inline', - treeShaking: true, - outfile: 'main.js', - }) - .catch(() => process.exit(1)); +const buildOptions = { + banner: { js: banner }, + entryPoints: ['src/main.ts'], + bundle: true, + external: ['obsidian', 'electron', ...builtins], + format: 'cjs', + target: 'es2016', + logLevel: 'info', + sourcemap: prod ? false : 'inline', + treeShaking: true, + outfile: 'main.js', +}; + +if (prod) { + esbuild.build(buildOptions).catch(() => process.exit(1)); +} else { + (async () => { + try { + const ctx = await esbuild.context(buildOptions); + await ctx.watch(); + console.log('Watching for changes...'); + } catch (e) { + process.exit(1); + } + })(); +} From a3459cdf025c2a3966b5d5b511e3a70b70ecdab1 Mon Sep 17 00:00:00 2001 From: willjasen Date: Sun, 23 Nov 2025 15:29:29 -0500 Subject: [PATCH 45/51] bump to version 0.4.4 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 66e4263..4de2a9b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-binary-file-manager-plugin", "name": "Binary File Manager", - "version": "0.4.3", + "version": "0.4.4", "minAppVersion": "0.12.0", "description": "Detects new binary files in the vault and creates markdown files with metadata.", "author": "qawatake, matthewturk, willjasen", From 93202febc56217dc2fb2fffc9e83910c94273c88 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 21 Apr 2026 17:53:56 -0400 Subject: [PATCH 46/51] fix pathing issue --- build.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index c64028e..78e9257 100755 --- a/build.sh +++ b/build.sh @@ -5,24 +5,26 @@ # variables SOURCE_DIR="/Users/willjasen/GitHub/obsidian-binary-file-manager-plugin"; -PLUGIN_DIR="/Users/willjasen/Obsidian/willjasen/.obsidian/plugins/obsidian-binary-file-manager-plugin"; +PLUGIN_DIR="/Users/willjasen/Library/Mobile Documents/iCloud~md~obsidian/Documents/willjasen/.obsidian/plugins/obsidian-binary-file-manager-plugin"; FILES=( "main.js" "manifest.json" "styles.css" ); -# Create the directory if needed -if [ -d $PLUGIN_DIR ]; then + +# Create the directory if needed (handle spaces and parents) +if [ -d "$PLUGIN_DIR" ]; then echo "Plugin directory already exists."; else - echo "Creating plugin directory at $PLUGIN_DIR"; mkdir $PLUGIN_DIR; + echo "Creating plugin directory at $PLUGIN_DIR"; mkdir -p "$PLUGIN_DIR"; fi # Go to the source directory and build this plugin -cd $SOURCE_DIR; + +cd "$SOURCE_DIR"; npm i --silent; npm run build > /dev/null 2>&1; # Copy built files into the plugin directory for file in "${FILES[@]}" do echo "Copying file: $file --> $PLUGIN_DIR/$file"; - cp $SOURCE_DIR/$file $PLUGIN_DIR/$file; + cp "$SOURCE_DIR/$file" "$PLUGIN_DIR/$file"; done echo "All files copied!"; \ No newline at end of file From 818c0144afcaaae80f13cb2804e9e5b06db96ac4 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 21 Apr 2026 17:54:14 -0400 Subject: [PATCH 47/51] add right-click option to create note where it is at --- src/Generator.ts | 73 ++++++++++++++++++++++-------------------------- src/main.ts | 32 +++++++++++++++++---- 2 files changed, 60 insertions(+), 45 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index 440c04a..75988e9 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -55,13 +55,20 @@ export class MetaDataGenerator { return true; } - async create(file: TFile) { + + /** + * Create a metadata note for a binary file. + * @param file The binary file + * @param baseDir Optional base directory for the note and attachments (default: plugin.settings.folder) + */ + async create(file: TFile, baseDir?: string) { + const folder = baseDir || this.plugin.settings.folder; + const attachmentsFolder = `${folder}/_attachments`; const metaDataFileName = this.uniquefyMetaDataFileName( - this.generateMetaDataFileName(file) + this.generateMetaDataFileName(file), folder ); - const metaDataFilePath = `${this.plugin.settings.folder}/${metaDataFileName}`; - - await this.createMetaDataFile(metaDataFilePath, file as TFile); + const metaDataFilePath = `${folder}/${metaDataFileName}`; + await this.createMetaDataFile(metaDataFilePath, file as TFile, attachmentsFolder); } private generateMetaDataFileName(file: TFile): string { @@ -73,9 +80,9 @@ export class MetaDataGenerator { return metaDataFileName; } - private uniquefyMetaDataFileName(metaDataFileName: string): string { + private uniquefyMetaDataFileName(metaDataFileName: string, folder: string): string { const metaDataFilePath = normalizePath( - `${this.plugin.settings.folder}/${metaDataFileName}` + `${folder}/${metaDataFileName}` ); if (this.app.vault.getAbstractFileByPath(metaDataFilePath)) { return `CONFLICT-${moment().format( @@ -86,12 +93,8 @@ export class MetaDataGenerator { } } - private uniquefyBinaryFileName(binaryFileName: string): string { - const binaryFilePath = normalizePath( - `${this.plugin.settings.folder}/${binaryFileName}` - ); - const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; - const attachmentFullFilePath = attachmentsFilePath+"/"+binaryFileName; + private uniquefyBinaryFileName(binaryFileName: string, attachmentsFolder: string): string { + const attachmentFullFilePath = attachmentsFolder+"/"+binaryFileName; if (this.app.vault.getAbstractFileByPath(attachmentFullFilePath)) { return `CONFLICT-${moment().format( 'YYYY-MM-DD-hh-mm-ss' @@ -102,44 +105,39 @@ export class MetaDataGenerator { } private async moveBinaryFile( - binaryFile: TFile - ): Promise { - - + binaryFile: TFile, + attachmentsFolder: string + ): Promise { const binaryFileName = this.uniquefyBinaryFileName( - binaryFile.basename+"."+binaryFile.extension + binaryFile.basename+"."+binaryFile.extension, + attachmentsFolder ); - const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; - const fullFilePath = attachmentsFilePath+"/"+binaryFileName; - + const fullFilePath = attachmentsFolder+"/"+binaryFileName; + // Ensure attachments folder exists + let folder = this.app.vault.getAbstractFileByPath(attachmentsFolder); + if (!folder) { + await this.app.vault.createFolder(attachmentsFolder); + } // move binary file into the attachments folder try { await this.app.fileManager.renameFile(binaryFile, fullFilePath); new Notice(`Binary file of ${binaryFileName} has been moved.`); + return fullFilePath; } catch (err) { new Notice(`Problem moving the binary file of ${binaryFileName} into the attachments folder.`); alert(err); + return binaryFile.path; } } private async createMetaDataFile( metaDataFilePath: string, - binaryFile: TFile + binaryFile: TFile, + attachmentsFolder: string ): Promise { - - // await sleep(1000); - const templateContent = await this.fetchTemplateContent(); - const attachmentsFilePath = `${this.plugin.settings.attachmentsFilePath}`; - const binaryFileName = binaryFile.basename+"."+binaryFile.extension; - const fullFilePath = attachmentsFilePath+"/"+binaryFileName; - - try { - await this.moveBinaryFile(binaryFile); - } catch(err) { - alert(err); - } - + // Move the binary file to the attachments folder + const fullFilePath = await this.moveBinaryFile(binaryFile, attachmentsFolder); // process by Templater const templaterPlugin = await this.getTemplaterPlugin(); if (!(this.plugin.settings.useTemplater && templaterPlugin)) { @@ -151,13 +149,11 @@ export class MetaDataGenerator { binaryFile.stat.ctime ) ); - } else { const targetFile = await this.app.vault.create( metaDataFilePath, '' ); - try { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore @@ -165,12 +161,11 @@ export class MetaDataGenerator { { target_file: targetFile, run_mode: 4 }, this.plugin.formatter.format( templateContent, - binaryFile.path, + fullFilePath, binaryFile.stat.ctime ) ); this.app.vault.modify(targetFile, content); - } catch (err) { new Notice( 'ERROR in Binary File Manager Plugin: failed to connect to Templater. Your Templater version may not be supported.' diff --git a/src/main.ts b/src/main.ts index e97aa1b..02a7961 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { FileManager, Notice, Plugin, TAbstractFile, TFile } from 'obsidian'; +import { Notice, Plugin, TAbstractFile, TFile } from 'obsidian'; import { Formatter } from 'Formatter'; import { BinaryFileManagerSettingTab } from 'Setting'; import { FileExtensionManager } from 'Extension'; @@ -46,11 +46,11 @@ const DEFAULT_SETTINGS: BinaryFileManagerSettings = { }; export default class BinaryFileManagerPlugin extends Plugin { - settings: BinaryFileManagerSettings; - formatter: Formatter; - metaDataGenerator: MetaDataGenerator; - fileExtensionManager: FileExtensionManager; - fileListAdapter: FileListAdapter; + settings!: BinaryFileManagerSettings; + formatter!: Formatter; + metaDataGenerator!: MetaDataGenerator; + fileExtensionManager!: FileExtensionManager; + fileListAdapter!: FileListAdapter; override async onload() { await this.loadSettings(); @@ -148,6 +148,26 @@ export default class BinaryFileManagerPlugin extends Plugin { // This adds a settings tab so the user can configure various aspects of the plugin this.addSettingTab(new BinaryFileManagerSettingTab(this.app, this)); + + // Add context menu option for binary files + this.registerEvent( + this.app.workspace.on('file-menu', (menu, file) => { + if (!(file instanceof TFile)) return; + const ext = this.fileExtensionManager.getExtensionMatchedBest(file.name); + if (!ext) return; + + menu.addItem((item) => { + item.setTitle('Move to _attachments and create note') + .setIcon('arrow-right') + .onClick(async () => { + // Use the file's current directory as the base + const fileDir = file.parent?.path || ''; + await this.metaDataGenerator.create(file, fileDir); + new Notice('Moved to _attachments and created note (with Templater if enabled, in current directory).'); + }); + }); + }) + ); } // onunload() {} From 66bf40c867ece68093d55ce72fb42b8647fbf1f5 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 21 Apr 2026 17:59:59 -0400 Subject: [PATCH 48/51] show extensions to be watched as chips --- src/Setting.ts | 24 +++++++++++++++--------- styles.css | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/Setting.ts b/src/Setting.ts index 442c206..1696620 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -184,16 +184,22 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { }); }); + + // Render extensions as inline chips + const extContainer = containerEl.createDiv('binary-file-manager-extensions-container'); this.plugin.settings.extensions.forEach((ext) => { - new Setting(containerEl).setName(ext).addExtraButton((cb) => { - cb.setIcon('cross').onClick(async () => { - this.plugin.fileExtensionManager.delete(ext); - this.plugin.settings.extensions = - this.plugin.fileExtensionManager.toArray(); - await this.plugin.saveSettings(); - this.display(); - }); - }); + const chip = extContainer.createDiv('binary-file-manager-extension-chip'); + chip.setText(ext); + const removeBtn = chip.createEl('button', { text: '✕' }); + removeBtn.addClass('remove-btn'); + removeBtn.setAttr('aria-label', `Remove ${ext}`); + removeBtn.onclick = async (e) => { + e.preventDefault(); + this.plugin.fileExtensionManager.delete(ext); + this.plugin.settings.extensions = this.plugin.fileExtensionManager.toArray(); + await this.plugin.saveSettings(); + this.display(); + }; }); new Setting(containerEl) diff --git a/styles.css b/styles.css index 13bb1c0..312f9aa 100644 --- a/styles.css +++ b/styles.css @@ -1,3 +1,40 @@ .binary-file-manager-text-error { color: var(--text-error); } + +.binary-file-manager-extensions-container { + display: flex; + flex-wrap: wrap; + gap: 0.5em; + margin-top: 0.5em; + margin-bottom: 1em; +} + +.binary-file-manager-extension-chip { + display: flex; + align-items: center; + background: var(--background-secondary-alt); + color: var(--text-normal); + border-radius: 1em; + padding: 0.2em 0.8em 0.2em 0.8em; + font-size: 0.95em; + margin: 0; + line-height: 1.5; + box-shadow: 0 1px 2px rgba(0,0,0,0.03); +} + +.binary-file-manager-extension-chip .remove-btn { + margin-left: 0.5em; + cursor: pointer; + color: var(--text-faint); + font-size: 1.1em; + border: none; + background: none; + padding: 0; + line-height: 1; + transition: color 0.15s; +} + +.binary-file-manager-extension-chip .remove-btn:hover { + color: var(--text-error); +} From f3e52c6a773fd31c22603f940803e40990749a25 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 21 Apr 2026 18:09:40 -0400 Subject: [PATCH 49/51] edit the notification --- src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 02a7961..d70fad8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -157,13 +157,13 @@ export default class BinaryFileManagerPlugin extends Plugin { if (!ext) return; menu.addItem((item) => { - item.setTitle('Move to _attachments and create note') + item.setTitle('Create note from binary file') .setIcon('arrow-right') .onClick(async () => { // Use the file's current directory as the base const fileDir = file.parent?.path || ''; await this.metaDataGenerator.create(file, fileDir); - new Notice('Moved to _attachments and created note (with Templater if enabled, in current directory).'); + new Notice(`Created note from "${file.name}" in "${fileDir}".`); }); }); }) From 727768a5a286c121c74d9fdb7930e5611f545fa1 Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 21 Apr 2026 18:16:35 -0400 Subject: [PATCH 50/51] use a different templater config for right-click --- src/Generator.ts | 26 ++++++++++++++++---------- src/Setting.ts | 38 +++++++++++++++++++++++++++----------- src/main.ts | 25 ++++++++++++++++--------- 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/src/Generator.ts b/src/Generator.ts index 75988e9..8add034 100644 --- a/src/Generator.ts +++ b/src/Generator.ts @@ -61,14 +61,20 @@ export class MetaDataGenerator { * @param file The binary file * @param baseDir Optional base directory for the note and attachments (default: plugin.settings.folder) */ - async create(file: TFile, baseDir?: string) { + /** + * Create a metadata note for a binary file. + * @param file The binary file + * @param baseDir Optional base directory for the note and attachments (default: plugin.settings.folder) + * @param templatePathOverride Optional template path to use instead of the default + */ + async create(file: TFile, baseDir?: string, templatePathOverride?: string) { const folder = baseDir || this.plugin.settings.folder; const attachmentsFolder = `${folder}/_attachments`; const metaDataFileName = this.uniquefyMetaDataFileName( this.generateMetaDataFileName(file), folder ); const metaDataFilePath = `${folder}/${metaDataFileName}`; - await this.createMetaDataFile(metaDataFilePath, file as TFile, attachmentsFolder); + await this.createMetaDataFile(metaDataFilePath, file as TFile, attachmentsFolder, templatePathOverride); } private generateMetaDataFileName(file: TFile): string { @@ -133,9 +139,10 @@ export class MetaDataGenerator { private async createMetaDataFile( metaDataFilePath: string, binaryFile: TFile, - attachmentsFolder: string + attachmentsFolder: string, + templatePathOverride?: string ): Promise { - const templateContent = await this.fetchTemplateContent(); + const templateContent = await this.fetchTemplateContent(templatePathOverride); // Move the binary file to the attachments folder const fullFilePath = await this.moveBinaryFile(binaryFile, attachmentsFolder); // process by Templater @@ -175,16 +182,15 @@ export class MetaDataGenerator { } } - private async fetchTemplateContent(): Promise { - if (this.plugin.settings.templatePath === '') { + private async fetchTemplateContent(templatePathOverride?: string): Promise { + const templatePath = templatePathOverride !== undefined ? templatePathOverride : this.plugin.settings.templatePath; + if (templatePath === '') { return DEFAULT_TEMPLATE_CONTENT; } const templateFile = await retry( () => { - return this.app.vault.getAbstractFileByPath( - this.plugin.settings.templatePath - ); + return this.app.vault.getAbstractFileByPath(templatePath); }, TIMEOUT_MILLISECOND, RETRY_NUMBER, @@ -192,7 +198,7 @@ export class MetaDataGenerator { ); if (!(templateFile instanceof TFile)) { - const msg = `Template file ${this.plugin.settings.templatePath} is invalid`; + const msg = `Template file ${templatePath} is invalid`; console.log(msg); new Notice(msg); return DEFAULT_TEMPLATE_CONTENT; diff --git a/src/Setting.ts b/src/Setting.ts index 1696620..9a8cf6f 100644 --- a/src/Setting.ts +++ b/src/Setting.ts @@ -139,21 +139,37 @@ export class BinaryFileManagerSettingTab extends PluginSettingTab { // Create the "Template file location" search setting and initially hide or show it const templateSetting = new Setting(containerEl) - .setName('Template file location') - .addSearch((component) => { - new FileSuggest(this.app, component.inputEl); - component - .setPlaceholder('Example: folder1/note') - .setValue(this.plugin.settings.templatePath) - .onChange((newTemplateFile) => { - this.plugin.settings.templatePath = newTemplateFile; - this.plugin.saveSettings(); - }); - }); + .setName('Template file location (watched folder)') + .addSearch((component) => { + new FileSuggest(this.app, component.inputEl); + component + .setPlaceholder('Example: folder1/note') + .setValue(this.plugin.settings.templatePath) + .onChange((newTemplateFile) => { + this.plugin.settings.templatePath = newTemplateFile; + this.plugin.saveSettings(); + }); + }); // Set the initial visibility of the "Template file location" setting templateSetting.settingEl.style.display = this.plugin.settings.useTemplater ? 'block' : 'none'; + // NEW: Context menu template path + const contextMenuTemplateSetting = new Setting(containerEl) + .setName('Template file location (context menu)') + .setDesc('Template to use when creating metadata from the right-click menu. Leave blank to use the default.') + .addSearch((component) => { + new FileSuggest(this.app, component.inputEl); + component + .setPlaceholder('Example: folder1/context-menu-template') + .setValue(this.plugin.settings.contextMenuTemplatePath) + .onChange((newTemplateFile) => { + this.plugin.settings.contextMenuTemplatePath = newTemplateFile; + this.plugin.saveSettings(); + }); + }); + contextMenuTemplateSetting.settingEl.style.display = this.plugin.settings.useTemplater ? 'block' : 'none'; + let extensionToBeAdded: string; new Setting(containerEl) diff --git a/src/main.ts b/src/main.ts index d70fad8..845d4c4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,6 +14,7 @@ interface BinaryFileManagerSettings { filenameFormat: string; templatePath: string; useTemplater: boolean; + contextMenuTemplatePath: string; // NEW: separate template for context menu } const DEFAULT_SETTINGS: BinaryFileManagerSettings = { @@ -42,7 +43,8 @@ const DEFAULT_SETTINGS: BinaryFileManagerSettings = { attachmentsFilePath: '/', filenameFormat: 'INFO_{{NAME}}_{{EXTENSION:UP}}', templatePath: '', - useTemplater: false + useTemplater: false, + contextMenuTemplatePath: '' }; export default class BinaryFileManagerPlugin extends Plugin { @@ -150,11 +152,11 @@ export default class BinaryFileManagerPlugin extends Plugin { this.addSettingTab(new BinaryFileManagerSettingTab(this.app, this)); // Add context menu option for binary files - this.registerEvent( - this.app.workspace.on('file-menu', (menu, file) => { - if (!(file instanceof TFile)) return; - const ext = this.fileExtensionManager.getExtensionMatchedBest(file.name); - if (!ext) return; + this.registerEvent( + this.app.workspace.on('file-menu', (menu, file) => { + if (!(file instanceof TFile)) return; + const ext = this.fileExtensionManager.getExtensionMatchedBest(file.name); + if (!ext) return; menu.addItem((item) => { item.setTitle('Create note from binary file') @@ -162,12 +164,17 @@ export default class BinaryFileManagerPlugin extends Plugin { .onClick(async () => { // Use the file's current directory as the base const fileDir = file.parent?.path || ''; - await this.metaDataGenerator.create(file, fileDir); + // Pass contextMenuTemplatePath as override + await this.metaDataGenerator.create( + file, + fileDir, + this.settings.contextMenuTemplatePath || undefined + ); new Notice(`Created note from "${file.name}" in "${fileDir}".`); }); }); - }) - ); + }) + ); } // onunload() {} From da086633db4c3787084e4c85bcc4541c11e30fdf Mon Sep 17 00:00:00 2001 From: willjasen Date: Tue, 21 Apr 2026 18:18:58 -0400 Subject: [PATCH 51/51] update version to 0.5.0 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 4de2a9b..fb7e94d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-binary-file-manager-plugin", "name": "Binary File Manager", - "version": "0.4.4", + "version": "0.5.0", "minAppVersion": "0.12.0", "description": "Detects new binary files in the vault and creates markdown files with metadata.", "author": "qawatake, matthewturk, willjasen",