Skip to content

Commit

Permalink
Update main.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsmallman authored Mar 26, 2023
1 parent 2903418 commit f7b8f39
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,37 @@ export default class TasksToOmnifocus extends Plugin {
}
},
});

this.addCommand({
id: 'extract-tasks-selection',
name: 'Extract Tasks from selection Into OmniFocus',
editorCallback: (editor: Editor, view: MarkdownView) => {
const editorText = editor.getSelection()
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.addSettingTab(new TasksToOmnifocusSettingTab(this.app, this));
}
Expand Down

0 comments on commit f7b8f39

Please sign in to comment.