nisus.com
https://www.nisus.com/forum/

Simple macro help for newbie
https://www.nisus.com/forum/viewtopic.php?f=17&t=5452
Page 1 of 1

Author:  miformby [ 2013-09-19 11:14:22 ]
Post subject:  Simple macro help for newbie

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

Author:  martin [ 2013-09-20 16:21:59 ]
Post subject:  Re: Simple macro help for newbie

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:
$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:
$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.

Author:  miformby [ 2013-09-24 14:57:42 ]
Post subject:  Re: Simple macro help for newbie

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

Author:  martin [ 2013-09-24 17:34:03 ]
Post subject:  Re: Simple macro help for newbie

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:
$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:
Define Command AppendSelectionToClipboard( $clipboardName )
   $selected = Read Selection
   Append to Clipboard $selected, $clipboardName
End

AppendSelectionToClipboard( "Clipboard 2" )



Quote:
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.

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/