registry problem (syntax?)

Get help using and writing Nisus Writer Pro macros.
Post Reply
Posts: 166
Joined: 2007-03-28 07:30:34

registry problem (syntax?)

Post by credneb » 2009-04-22 14:16:33

So I'm making progress learning the new macro language and have several macros that work well, thanks to Martin and others. Among those are a couple that save values using the registry objects. Starting small to big, my macro for adding single glossary entries works as desired, including opening the job-specific glossary file by calling the macro shown below.

The current problem is that while I have no problem in other macros saving an application.Registry variable, recalling it and updating it each time, the following code (which seems to be the same as in the examples and my other macros that work vis saving/reading a registry variable) does not save the registry variable.

I'm completely stumped and would greatly appreciate your help again. The entire macro (which is called from another macro because I will use in other macros) follows. Nisus doesn't burp and give my any errors. All of the prompts with numbers simply give feedback while checking to see where I screwed up. As far as I can tell, it should be OK (but obviously it ain't).

Each job has a unique ID, and each glossary created for each job is unique to the job ID. The only parts that don't work are reading and saving $lastSaved and $lastUsed. If instead of
$lastUsed = 'NewGlossary'
$lastUsed is hardwired to the glossary (e.g., "J123456g.ngloss"), the macro works as desired, i.e, it simply opens the glossary file (already created). But $lastUsed does not get saved when the glossary is selected from the prompt.

The idea is that because 99% of the time additions are made to the job glossary, the logic is
IF last glossary used = current job glossary
open glossary and edit
present selection dialog

(I have a macro that presents a dialog for selecting the desired glossary, as desired, but it also will not save the $lastSaved glossary.)

But I'm obviously doing something wrong, syntax somewhere. Help, please.

Code: Select all

#load list of glossary files

Require Pro Version 1.2
$doc =
$hasDoc = Defined $doc
If ! $hasDoc
	Prompt "You need to open a document."
$path = $doc.filePath
$hasPath = Defined $path
If ! $hasPath
	Prompt "Save the document first."

	#get the name of the last glossary used; save the glossary used at the end
$registry = Registry.applicationRegistry
$lastSaved = 'com.j2e.glossaryMacros.lastGlossarySaved'
$lastUsed = $registry.loadValueWithName($lastSaved)
Prompt "1 lastSaved = "&$registry.loadValueWithName($lastSaved)
If $lastUsed == undefined
	Prompt '2 har de har it\'s not defined'
	$lastUsed = 'NewGlossary'
	Prompt "3 lastUsed = $lastUsed"
	$registry.saveValueWithName($lastSaved, $lastUsed)

	#extract the name of the glossary for the current job
$jobName = $doc.displayName
$loc = $jobName.rangeOfString('.')
if Defined($loc)
	$range =,$loc)
	$jobNumber = $jobName.subtextInRange($range)
$currentJobGlossary = $jobNumber&'g.ngloss'

	#now get list of glossaries in glossary folder
$glossaryFolderPath = '~/Library/Application Support/Nisus Writer/Glossaries'
$glossariesInFolder = File.namesInFolderAtPath $glossaryFolderPath

	#discover if job glossary is in folder
$index = $glossariesInFolder.indexOfValue($currentJobGlossary)
If $index == -1
	Prompt 'The job glossary does not exist.'
elseif $index > 0
		#insert the glossary derived from document title to beginning of array
		#to make it the default
	$glossariesInFolder.prependValue $currentJobGlossary

Prompt "4 the lastUsed = $lastUsed"
Prompt "5 the lastSaved = $lastSaved"
Prompt "6 the currentJobGlossary = $currentJobGlossary"

If $lastUsed == $currentJobGlossary
	$glossaryPath = $glossaryFolderPath.filePathByAppendingComponent($currentJobGlossary)
	Open $glossaryPath
	$message = 'Select the glossary to edit.'
	$gloss = Prompt Options $message, '', 'Select', $glossariesInFolder
	Prompt "7 the selected glossary is $gloss"
	$registry.saveValueWithName($lastSaved, $gloss)
	$glossaryPath = $glossaryFolderPath.filePathByAppendingComponent($gloss)
	Open $glossaryPath


Official Nisus Person
Posts: 4618
Joined: 2002-07-11 17:14:10
Location: San Diego, CA

Re: registry problem (syntax?)

Post by martin » 2009-04-22 16:11:11

I haven't tried to understand exactly what your macro is designed to do, but it seems to me that you have reversed the order of the name/value arguments when saving to the registry. Looking at:

Code: Select all

$registry.saveValueWithName($lastSaved, $gloss)
I think it should be:

Code: Select all

$registry.saveValueWithName($gloss, $lastSaved)
Likewise with your other "save" command.

Posts: 166
Joined: 2007-03-28 07:30:34

Re: registry problem (syntax?)

Post by credneb » 2009-04-23 06:18:28


Thank you very much. No need to understand the whole thing. That was all it was.

And now it's easier to remember ... save *Value* With *Name*...

Cliff Bender

Post Reply