mirror of
https://github.com/tmfelwu/obsidian-inbox.git
synced 2026-07-22 07:40:30 +00:00
added all
This commit is contained in:
commit
cb93c37c47
8 changed files with 406 additions and 0 deletions
151
.gitignore
vendored
Normal file
151
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
# Created by https://www.toptal.com/developers/gitignore/api/obsidian,node
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=obsidian,node
|
||||
|
||||
|
||||
main.js
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
### Node Patch ###
|
||||
# Serverless Webpack directories
|
||||
.webpack/
|
||||
|
||||
# Optional stylelint cache
|
||||
|
||||
# SvelteKit build / generate output
|
||||
.svelte-kit
|
||||
|
||||
### Obsidian ###
|
||||
# config dir
|
||||
.obsidian/
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/obsidian,node
|
||||
76
README.md
Normal file
76
README.md
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
|
||||
|
||||
|
||||
|
||||
To create a global shortcut for the Obsidian plugin that can be used from anywhere in the operating system, you'll need to use an external tool to set up a system-wide hotkey. This hotkey will then be used to trigger a custom URL that opens Obsidian and runs the plugin command. Here's how to do it for different operating systems:
|
||||
|
||||
1. **Create a custom URL scheme for the plugin command:**
|
||||
|
||||
First, you need to create a custom URL that will open Obsidian and execute the plugin command. This URL will be used by the external tool to trigger the plugin. Update the `onload` method in the `main.ts` file of your plugin to register a URL handler:
|
||||
|
||||
```typescript
|
||||
async onload() {
|
||||
this.registerObsidianProtocolHandler('quick-capture', async (params) => {
|
||||
const targetNoteTitle = 'Inbox'; // You can change this to any note title you prefer
|
||||
const targetNote = this.app.vault.getAbstractFileByPath(`${targetNoteTitle}.md`);
|
||||
const capturedText = await this.promptForText();
|
||||
|
||||
if (capturedText) {
|
||||
await this.appendTextToNote(targetNote, capturedText);
|
||||
}
|
||||
});
|
||||
|
||||
// ... rest of the onload method
|
||||
}
|
||||
```
|
||||
|
||||
Now you can use the custom URL `obsidian://quick-capture` to trigger the plugin command.
|
||||
|
||||
2. **Set up a global hotkey using an external tool:**
|
||||
|
||||
**For Windows:**
|
||||
|
||||
You can use a tool like AutoHotkey to set up a global hotkey. Follow these steps:
|
||||
|
||||
1. Install AutoHotkey from https://www.autohotkey.com/.
|
||||
2. Create a new text file with the extension `.ahk`, e.g., `ObsidianQuickCapture.ahk`.
|
||||
3. Add the following script to the file (replace `^!c` with your preferred hotkey combination, e.g., `^!c` stands for Ctrl + Alt + C):
|
||||
|
||||
```autohotkey
|
||||
^!c::
|
||||
Run, obsidian://quick-capture
|
||||
return
|
||||
```
|
||||
|
||||
4. Double-click the `.ahk` file to run the script. The global hotkey should now be active.
|
||||
|
||||
**For macOS:**
|
||||
|
||||
You can use a tool like BetterTouchTool or Keyboard Maestro to set up a global hotkey. Here's how to do it with BetterTouchTool:
|
||||
|
||||
1. Install BetterTouchTool from https://folivora.ai/.
|
||||
2. Open BetterTouchTool and go to the "All Apps" section.
|
||||
3. Click on the "+" button to add a new global shortcut.
|
||||
4. Press the desired key combination for the hotkey.
|
||||
5. In the "Trigger Predefined Action" dropdown, select "Controlling Other Applications" > "Open URL / Open URL with Selection".
|
||||
6. Enter the custom URL `obsidian://quick-capture` and click "Save".
|
||||
|
||||
Now the global hotkey should be active and trigger the plugin command from anywhere in your operating system.
|
||||
|
||||
**For ubuntu**
|
||||
On Ubuntu 22.04, you can set up a global hotkey to trigger the Obsidian plugin command using the built-in keyboard shortcut settings.
|
||||
|
||||
1. Open the "Settings" application.
|
||||
2. Click on "Keyboard & Mouse" in the left sidebar.
|
||||
3. Click on the "Customize Shortcuts" button.
|
||||
4. Scroll down to the "Custom Shortcuts" section and click the "+" button to add a new shortcut.
|
||||
5. In the "Add Custom Shortcut" dialog, enter the following information:
|
||||
|
||||
- Name: `Obsidian Quick Capture`
|
||||
- Command: `xdg-open "obsidian://quick-capture"`
|
||||
|
||||
6. Click the "Add" button to create the custom shortcut.
|
||||
7. Click on the "Disabled" text next to the new shortcut in the list. Press the desired key combination for the hotkey (e.g., Ctrl + Alt + C).
|
||||
8. Close the settings application.
|
||||
|
||||
Now the global hotkey should be active and trigger the plugin command from anywhere in your operating system.
|
||||
82
main.ts
Normal file
82
main.ts
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
import { Plugin, Modal } from 'obsidian';
|
||||
|
||||
class TextInputModal extends Modal {
|
||||
private textarea: HTMLTextAreaElement;
|
||||
|
||||
constructor(app, private onSubmit: (value: string) => void) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
onOpen() {
|
||||
this.textarea = document.createElement('textarea');
|
||||
this.textarea.rows = 5;
|
||||
this.textarea.placeholder = 'Enter to capture';
|
||||
this.textarea.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'Enter' && event.ctrlKey) {
|
||||
this.onSubmit(this.textarea.value);
|
||||
this.close();
|
||||
} else if (event.key === 'Escape') {
|
||||
this.close();
|
||||
}
|
||||
});
|
||||
this.contentEl.appendChild(this.textarea);
|
||||
}
|
||||
|
||||
onClose() {
|
||||
this.textarea.remove();
|
||||
}
|
||||
}
|
||||
|
||||
export default class QuickCaptureToNotePlugin extends Plugin {
|
||||
async onload() {
|
||||
this.addCommand({
|
||||
id: 'quick-capture-to-note',
|
||||
name: 'Quick Capture to Note',
|
||||
callback: () => this.openCaptureModal(),
|
||||
});
|
||||
|
||||
this.registerObsidianProtocolHandler('quick-capture', () => {
|
||||
this.openCaptureModal();
|
||||
});
|
||||
} async onload() {
|
||||
this.addCommand({
|
||||
id: 'quick-capture-to-note',
|
||||
name: 'Quick Capture to Note',
|
||||
callback: () => this.openCaptureModal(),
|
||||
});
|
||||
|
||||
this.registerObsidianProtocolHandler('quick-capture', () => {
|
||||
this.openCaptureModal();
|
||||
});
|
||||
}
|
||||
|
||||
openCaptureModal() {
|
||||
const targetNoteTitle = 'Inbox'; // You can change this to any note title you prefer
|
||||
const targetNote = this.app.vault.getAbstractFileByPath(`${targetNoteTitle}.md`);
|
||||
|
||||
const modal = new TextInputModal(this.app, async (capturedText) => {
|
||||
if (capturedText) {
|
||||
await this.appendTextToNote(targetNote, capturedText);
|
||||
}
|
||||
});
|
||||
modal.open();
|
||||
}
|
||||
|
||||
async appendTextToNote(note, text) {
|
||||
if (note) {
|
||||
const currentContent = await this.app.vault.read(note);
|
||||
const newContent = currentContent + '\n' + text;
|
||||
await this.app.vault.modify(note, newContent);
|
||||
|
||||
// Open the note and set the cursor position to the end of the note
|
||||
const leaf = this.app.workspace.activeLeaf;
|
||||
const editor = await leaf.openFile(note, { state: { mode: 'source' } });
|
||||
editor.setCursor(editor.lineCount(), 0);
|
||||
} else {
|
||||
console.error('Target note not found');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
8
manifest.json
Normal file
8
manifest.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"id": "obsidian-inbox",
|
||||
"name": "Obsidian Inbox",
|
||||
"version": "0.1.0",
|
||||
"author": "Sparsh",
|
||||
"description": "Quickly capture text and append it to the end of a note.",
|
||||
"minAppVersion": "0.12.0"
|
||||
}
|
||||
31
package-lock.json
generated
Normal file
31
package-lock.json
generated
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "obsidian-inbox",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
"typescript": "^5.0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.0.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz",
|
||||
"integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.20"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"typescript": {
|
||||
"version": "5.0.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz",
|
||||
"integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw=="
|
||||
}
|
||||
}
|
||||
}
|
||||
8
package.json
Normal file
8
package.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"obsidian": "^0.12.0"
|
||||
}
|
||||
}
|
||||
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2017",
|
||||
"module": "commonjs",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["*.ts"]
|
||||
}
|
||||
40
yarn.lock
Normal file
40
yarn.lock
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/codemirror@0.0.108":
|
||||
version "0.0.108"
|
||||
resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-0.0.108.tgz#e640422b666bf49251b384c390cdeb2362585bde"
|
||||
integrity sha512-3FGFcus0P7C2UOGCNUVENqObEb4SFk+S8Dnxq7K6aIsLVs/vDtlangl3PEO0ykaKXyK56swVF6Nho7VsA44uhw==
|
||||
dependencies:
|
||||
"@types/tern" "*"
|
||||
|
||||
"@types/estree@*":
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2"
|
||||
integrity sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==
|
||||
|
||||
"@types/tern@*":
|
||||
version "0.23.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/tern/-/tern-0.23.4.tgz#03926eb13dbeaf3ae0d390caf706b2643a0127fb"
|
||||
integrity sha512-JAUw1iXGO1qaWwEOzxTKJZ/5JxVeON9kvGZ/osgZaJImBnyjyn0cjovPsf6FNLmyGY8Vw9DoXZCMlfMkMwHRWg==
|
||||
dependencies:
|
||||
"@types/estree" "*"
|
||||
|
||||
moment@2.29.1:
|
||||
version "2.29.1"
|
||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
|
||||
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
|
||||
|
||||
obsidian@^0.12.0:
|
||||
version "0.12.17"
|
||||
resolved "https://registry.yarnpkg.com/obsidian/-/obsidian-0.12.17.tgz#8efe75310d0e3988cdeccfbb176d3a8ff7b363c7"
|
||||
integrity sha512-YvCAlRym9D8zNPXt6Ez8QubSTVGoChx6lb58zqI13Dcrz3l1lgUO+pcOGDiD5Qa67nzDZLXo3aV2rqkCCpTvGQ==
|
||||
dependencies:
|
||||
"@types/codemirror" "0.0.108"
|
||||
moment "2.29.1"
|
||||
|
||||
typescript@^5.0.4:
|
||||
version "5.0.4"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b"
|
||||
integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==
|
||||
Loading…
Reference in a new issue