This commit is contained in:
lizard-heart 2023-03-26 11:20:53 -07:00
parent b7aecc8ad6
commit 05e7ef1219
2 changed files with 30 additions and 87 deletions

View file

@ -1,7 +1,7 @@
{
"id": "tasks-to-omnifocus",
"name": "Send Tasks to OmniFocus",
"version": "1.0.5",
"version": "1.0.6",
"minAppVersion": "0.12.0",
"description": "An Obsidian plugin will extract tasks from the current note and create them in OmniFocus.",
"author": "Henry Gustafson",

View file

@ -21,40 +21,13 @@ export default class TasksToOmnifocus extends Plugin {
async onload() {
await this.loadSettings();
// this.addCommand({
// id: "extract-tasks",
// name: "Extract Tasks Into OmniFocus",
// callback: () => this.sendToOF(),
// });
this.addCommand({
id: 'extract-tasks',
name: 'Extract Tasks Into OmniFocus',
editorCallback: (editor: Editor, view: MarkdownView) => {
const editorText = editor.getValue()
try {
let tasks = editorText.match(/- \[ \] .*/g);
for (let task of tasks) {
let taskName = task.replace("- [ ] ", "");
let taskNameEncoded = encodeURIComponent(taskName);
let noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F");
let vaultName = app.vault.getName();
let taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file=" + noteURL);
window.open(
`omnifocus:///add?name=${taskNameEncoded}&note=${taskNoteEncoded}`
);
}
if (this.settings.markComplete) {
let completedText = editorText.replace(/- \[ \]/g, "- [x]");
editor.setValue(completedText);
}
} catch (err) {
}
this.addToOmnifocus(editorText, editor, view);
},
});
@ -62,7 +35,15 @@ export default class TasksToOmnifocus extends Plugin {
id: 'extract-tasks-selection',
name: 'Extract Tasks from selection Into OmniFocus',
editorCallback: (editor: Editor, view: MarkdownView) => {
const editorText = editor.getSelection()
const editorText = editor.getSelection();
this.addToOmnifocus(editorText, editor, view);
},
});
this.addSettingTab(new TasksToOmnifocusSettingTab(this.app, this));
}
async addToOmnifocus(editorText: string, editor: Editor, view: MarkdownView) {
try {
let tasks = editorText.match(/- \[ \] .*/g);
@ -86,10 +67,6 @@ export default class TasksToOmnifocus extends Plugin {
} catch (err) {
}
},
});
this.addSettingTab(new TasksToOmnifocusSettingTab(this.app, this));
}
async saveSettings() {
@ -98,40 +75,6 @@ export default class TasksToOmnifocus extends Plugin {
onunload() {}
// // the first function that runs
// async sendToOF() {
// // const app = window.app as App;
// const view = this.app.workspace.getActiveViewOfType(MarkdownView);
// if (view!=null) {
// const editor = view.editor;
// const editorText = editor.getValue();
// try {
// let tasks = editorText.match(/- \[ \] .*/g);
// for (let task of tasks) {
// let taskName = task.replace("- [ ] ", "");
// let taskNameEncoded = encodeURIComponent(taskName);
// let noteURL = view.file.path.replace(/ /g, "%20").replace(/\//g, "%2F");
// let vaultName = app.vault.getName();
// let taskNoteEncoded = encodeURIComponent("obsidian://open?=" + vaultName + "&file="+noteURL);
// window.open(
// `omnifocus:///add?name=${taskNameEncoded}&note=${taskNoteEncoded}`
// );
// }
// if (this.settings.markComplete) {
// let completedText = editorText.replace(/- \[ \]/g, "- [x]");
// editor.setValue(completedText);
// }
// } catch (err) {
// }
// }
// }
private async loadSettings() {
this.settings = Object.assign(