Simple macro help for newbie

Get help using and writing Nisus Writer Pro macros.
Post Reply
miformby
Posts: 2
Joined: 2013-09-19 10:50:10

Simple macro help for newbie

Post by miformby » 2013-09-19 11:14:22

I'm sorry to be so lazy, but I need two very simple macros to emulate and improve on Word's Cut To Spike feature. I need one macro to Copy Append text to another clipboard (say clipboard 2) without changing the current clipboard. And one to Cut Append text in the same manner.

Thanks in advance,
Millard

User avatar
martin
Official Nisus Person
Posts: 4361
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Simple macro help for newbie

Post by martin » 2013-09-20 16:21:59

Hi Millard: these are relatively easy macros to write. Let's look at few ways we might tackle the problem.

1. This code works to quickly change the active clipboard before and after the copy/cut:

Code: Select all

$originalName = Clipboard Name # save current clipboard name so we can restore it
Switch To Clipboard "Clipboard 2"
Append Copy
Switch To Clipboard $originalName
If you want a version that does a cut instead of a copy, just change "Append Copy" to "Append Cut".


2. This code doesn't actually change the active clipboard at any point, instead it directly modifies the clipboard contents:

Code: Select all

$selected = Read Selection
$clipboard = Read Clipboard "Clipboard 2"
$joined = $clipboard & $selected
Write Clipboard $joined, "Clipboard 2"
If you want a version that does a cut, just insert a "Delete" command at the very end.

I hope that helps. Let us know if you have any questions.

miformby
Posts: 2
Joined: 2013-09-19 10:50:10

Re: Simple macro help for newbie

Post by miformby » 2013-09-24 14:57:42

Thanks Martin, that is just what I needed. So there is no function to copy or copy append to a non-active clipboard, only write? Also, could you advise a place to start to learn the Nisus' macro language? I used to write simple macros like this with the old Nisus, but it seems very different now. Should I just get a book on Perl? Or is there a better way to get started?

Thanks again,
Millard

User avatar
martin
Official Nisus Person
Posts: 4361
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Simple macro help for newbie

Post by martin » 2013-09-24 17:34:03

miformby wrote:So there is no function to copy or copy append to a non-active clipboard, only write?
Actually, now that you mention it, the macro language does have a command for that. I just missed it when answering initially. So you could simplify the entire macro to just:

Code: Select all

$selected = Read Selection
Append to Clipboard $selected, "Clipboard 2"
I should point out that the macro language also lets you define your own commands. So if you are writing a macro that appends the selection to a clipboard a lot, you might do something like this:

Code: Select all

Define Command AppendSelectionToClipboard( $clipboardName )
	$selected = Read Selection
	Append to Clipboard $selected, $clipboardName
End

AppendSelectionToClipboard( "Clipboard 2" )
Also, could you advise a place to start to learn the Nisus' macro language? I used to write simple macros like this with the old Nisus, but it seems very different now. Should I just get a book on Perl?
I don't think a book on Perl would be too helpful, because these days you don't need to use Perl blocks very often, as the built-in NWP macro language has grown. Unfortunately there aren't any great resources on learning NWP macros. There is the Macro Language References (on the Help menu), but that's really intended primarily as a litany of what the language is capable of, not a teaching tool for beginners.

Sorry to not have a better answer. You can always ask questions or request macros here on the forum and we'll try to help out as best we can.

Post Reply