TLDR: Every time I navigate to a tiddler with the tag “book”, I want the title of the tiddler to be automatically saved to the clipboard.
Any way to do this?
My actual problem, for those interested:
When taking notes from books I pretty much always add a citation like <<source MyBook>>. To make this less tedious I have a keyboard shortcut that adds the citation for me, based on the last tiddler that I navigated to (which is usually the “book” tiddler).
This works for me on desktop, but of course I can’t use keyboard shortcuts on mobile. I’m thinking of using a text expander instead, but this means getting access to the last-navigated-to-tiddler from an app outside of TiddlyWiki. My thinking was to store this in the clipboard with tm-copy-to-clipboard, but to do this I think I would need to run an action widget every time I navigate to a “book” tiddler.
I’m trying to avoid adding extra buttons and stuff.
Surround links to books with a LinkCatcherWidget, which you can use to both navigate to the target tiddler and copy the title to the clip board.
I’m sure this would be a pain to do for every single link to a book, but there may be some ways you might not need to. Here’s just one idea of how that might be achievable through light “hacking” of the story river (using the Story Tiddler Template Cascade):
Make a tiddler with LinkCatcherWidget as described above, except one that conditionally copies to clipboard only if the navigate-to tiddler is tagged Book.
Inside the link catcher widget, transclude the View Template (I think you have to do this without setting the current tiddler.) You could perhaps name this one “(yourDesiredPrefix)/ViewTemplateWrapper”
Create a second tiddler, tagged $:/tags/StoryTiddlerTemplateFilter and add list-before: $:/config/StoryTiddlerTemplateFilters/default and in the text field write [[(yourDesiredPrefix)/ViewTemplateWrapper]] (or whatever you named the first tiddler).
This should, in effect, surround all tiddlers in the story river (except those in edit mode) with the LinkCatcherWidget so you only need to write it once, without changing anything about how you write links, nor any of your existing code.
@TW_Tones 's suggestion to use the Page Template would be more comprehensive in that it would catch links in places other than the story river. I imagine it would be extremely easy to do just by modifying the Page Template tiddler to surround the contents with the widget; however, it might be very difficult to do it without overriding any shadow tiddlers.
If you want to avoid overriding shadow tiddlers, my suggestion may be easier to do, since you can utilize the existing template by transclusion rather than by editing, and use the cascade mechanism to insert the needed tiddler into the story river cascade, all without touching any shadows.
But if you’re not concerned about modifying shadow tiddlers, modifying the Page Template is probably a better choice.
I only really need to catch links within the story river I think. I’ve got it working by editing $:/core/ui/PageTemplate/story as @TW_Tones suggested.
I would prefer to avoid modifying any shadow tiddlers, but for some reason @bluepenguindeveloper’s suggestion works perfectly except that it breaks scrolling to opened tiddlers. Clicking on links opens the tiddler, but doesn’t scroll to it!
I forgot about this and also couldn’t find anything in the docs about a way to do something like that. But sure enough, it’s right there in the Control Panel.
Which means that yes, you can create a copy and switch (which has one of the same downsides as overriding shadow tiddlers, namely that you won’t get the updates if the page template is updated in a new TW version), or you can transclude the default page template rather than copying it.
I think you have a better solution now that we know you can switch the page template without editing the existing one (and possibly another solution via the hook, though that is beyond my knowledge), so I’m not concerned about “solving” it, but I am curious if anyone happens to have any ideas as to why this broke scrolling.
The hook is handled by the root widget and so I don’t think it would be possible to send messages from it and that would mean calling action widgets would be a problem.
I would be nice to be able to ‘monkey patch’ core templates, ie transclude the shadow tiddler from a overridden tiddler in an easy way. Also the $messagecatcher widget could do with a ‘resend’ option to resend the message it caught.
The th-navigating hook is called by the navigator-widget right before it actually takes any action.
So the th-navigating hook is intended to allow modification to the event eg: .navigateTo or any other variable, that will be used afterwards by the code.