Style definition with macro

Everything related to our flagship word processor.
Post Reply
tedg
Posts: 42
Joined: 2012-09-22 01:52:56
Location: Brisbane, Australia
Contact:

Style definition with macro

Post by tedg »

Feature request:

I would like the ability to define a macro to execute whenever a style is applied. My use case is for headers to apply a title case macro, but I can think of others I may want.

I know I can do this now by writing a macro that applies a style and performs the macro, but that doesn't integrate with the style management system.
User since 1990
Most current NWp and MacOS
MacBookPro 16-inch 2021
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Style definition with macro

Post by martin »

Thanks for the suggestion. I'll add your vote for this feature, which is more generally expressed as the desire to automatically run macros after certain special events, eg: open a document, invoke a menu, etc. I'll make a note that applying a style could also be a useful macro trigger.

In the meantime, writing a macro that applies a style is likely your best and only solution.
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Style definition with macro

Post by Þorvarður »

martin wrote: 2021-04-20 08:43:41 this feature, which is more generally expressed as the desire to automatically run macros after certain special events, eg: open a document, invoke a menu, etc.
Thanks Martin for putting the original poster's request into a broader context. I had first no idea why he was asking for a feature like this. Now I understand.

Nisus Writer 6.5 had this feature. We could run a macro when a certain document was opened, but the best thing was being able to hide a long macro behind a single word or a text string. I absolutely loved that feature.

Count my vote for macros behind text. :–)
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Style definition with macro

Post by martin »

Þorvarður wrote: 2021-04-21 09:18:47 Nisus Writer 6.5 had this feature. We could run a macro when a certain document was opened, but the best thing was being able to hide a long macro behind a single word or a text string. I absolutely loved that feature.

Count my vote for macros behind text. :–)
Thanks for the vote Þorvarður! But I have one question about "macros behind text". Do you mean something like a hyperlink that runs a macro? If, so then this is already possible.

Macros can already create and apply links that run other macros. Here's such a macro:

Code: Select all

$link = Link.newRunMacroWithMenuPath "Macro:Application:Show All Menu Key Shortcuts"
$link.apply
To use this macro:
1. Open any document.
2. Select any piece of text in the document.
3. Run the above macro.

You will see a hyperlink applied to the selected text. If you click the linked text a macro will run: the macro specified by the menu path. For more options see the Link object in the Nisus Writer Macro Language reference. There are a variety of available commands to create macro links:

Code: Select all

Link.newRunMacroWithMenuPath
Link.newRunMacroWithFilePath
Link.newRunThisMacro
Please let me know if you have any questions.
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Style definition with macro

Post by Þorvarður »

martin wrote: 2021-04-22 09:03:01 You will see a hyperlink applied to the selected text.
Wow! Didn't know that this was possible. Nisus is full of surprises…

About "macros behind text":
In the Classic version I remember vaguely being able to right-click (?) on a word and a small window would then be opened where I could place the macro. It was possible to tell the macro to run only if I pressed the Shift key (option key, command key, and perhaps other modifier keys as well.) Thus I could run 3 (or more?) different macros depending on which modifier key I pressed when I clicked on the word. This was long time ago, so I can't remember all the details.

I found this useful for language studies. In document A I had the text book, in document B the grammar and in document C the vocabulary. Opening one of them would automatically open the others too. When I clicked on a word in the text book (with a modifier key) I could jump right to that word in the vocabulary file. Clicking again would take me back to where I left off. Clicking on the word with another modifier key would take me to the word in the grammar file, and so forth. I think I was also able to record sound (pronunciation.)

Perhaps all this can now be done with link commands. I'll have to experiment with this and see…

Thanks Martin for drawing my attention to the fact that macros can already create and apply links that run other macros. Also thanks for this wonderful word processor and your constant readiness to help and assist in the forum.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Style definition with macro

Post by martin »

Þorvarður wrote: 2021-04-23 08:48:22About "macros behind text":
In the Classic version I remember vaguely being able to right-click (?) on a word and a small window would then be opened where I could place the macro. It was possible to tell the macro to run only if I pressed the Shift key (option key, command key, and perhaps other modifier keys as well.) Thus I could run 3 (or more?) different macros depending on which modifier key I pressed when I clicked on the word. This was long time ago, so I can't remember all the details.
Thanks for describing this old classic feature to me. It's nice to have such knowledgeable and friendly users that they can fill you in on Nisus history! The quick macro access you described sounds pretty cool and useful. I'll file it as another potential enhancement, thanks :)
Post Reply