macstories / obsidian-shortcut-launcher

Trigger shortcuts in Apple's Shortcuts app from Obsidian with custom commands.
MIT License
187 stars 10 forks source link

Receiving result value from Shortcut? #2

Open ankushg opened 2 years ago

ankushg commented 2 years ago

This is pretty sweet!

I'd previously hacked together some stuff using URL schemes to run Shortcuts, but having them explicitly listed as commands is definitely better 😄

Is there a nice way to insert the the output of an executed Shortcut back into a file in Obsidian?

I've currently been using a technique similar to this: https://forum.obsidian.md/t/ical-daily-schedule-via-ios-osx-shortcut/30686

colintedford commented 2 years ago

I haven't actually worked with files in Shortcuts yet, but you could use the Copy To Clipboard action at the end of your shortcut and then paste the output where you want it.

If you just want to add the output to the end of the file, and your launcher sends the file's path along with its other info, you can use the Append to Text File action in Shortcuts.

I don't think there's a way to tell Shortcuts where the cursor is so it can put text there. You could put a placeholder where you want the output (as in the technique you linked), have the launcher send the entire document (along with any other info) to the shortcut, use the Replace Text action, then use Rename File on the original file (to avoid deleting it before you've saved the new version), Save File to put the updated text in a new file with the original filename, and Delete Files on the old version of the file (or maybe you could use Move File to put it in Obsidian's trash folder). You might be able to just Save File over the old version (perhaps with a prompt to confirm)— I don't know.

Again, I haven't yet worked with files in Shortcuts, but hopefully this will give you a place to start from.

finnvoor commented 2 years ago

You could use the Obsidian URI scheme (or obsidian-advanced-uri) to add actions at the end of shortcuts that you run that can then edit or create notes in Obsidian with the output. For example, you can pass the document path to the shortcut you run, and at the end of the shortcut add an action that opens the URL obsidian://advanced-uri?vault=<your-vault>&filepath=<document-path>&data=<shortcut-output>&mode=append to append the output of the shortcut to the document you run the shortcut from.

lzilioli commented 9 months ago

This issue is related to/a duplicate of #7

lzilioli-prism commented 4 months ago

I opened a PR for this a few months back: https://github.com/macstories/obsidian-shortcut-launcher/pull/13