Macros don't work

Get help using and writing Nisus Writer Pro macros.
Post Reply
Windsor
Posts: 46
Joined: 2008-04-28 22:10:11
Contact:

Macros don't work

Post by Windsor » 2010-12-21 19:14:00

Can anyone guess why a few macros, that used to work in Mac OS Tiger, and now does not work in Snow Leopard? When I activate one of the three macros (all of them stopped working), nothing happens. They used to open up a new file and import the finished work in almost lightning speed, and now, it takes for ever and nothing happens. I have to quit the program, otherwise the whole computer slows down. Any suggestions?

thanx,
Windsor

User avatar
phspaelti
Posts: 948
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Macros don't work

Post by phspaelti » 2010-12-22 06:41:29

Hello Windsor,
without some more information it's hard to say anything. Where did you get these macros from? Are they Nisus macros or perl macros? Were you using the same version of Nisus?
philip

Windsor
Posts: 46
Joined: 2008-04-28 22:10:11
Contact:

Re: Macros don't work

Post by Windsor » 2010-12-22 09:18:39

Those macros are made by Nisus for me. I've been using Nisus Writer Pro for a long time now. And the macros are .nwm (I guess not perl). These macros are to create a word list using the unicode font, specifically the Armenian font. I hope these infos will help you in finding the problem.

Thanx,
Windsor

Windsor
Posts: 46
Joined: 2008-04-28 22:10:11
Contact:

Re: Macros don't work

Post by Windsor » 2010-12-22 09:50:58

Interesting things happened, right after I posted a reply to you.
1. I noticed the logo of those macros were blank. So I opened them in Nisus and re saved them as: the same title. And now they have the Nisus logo.
2. Ran the macro: "CompleteWordList.nwm"
3. It took 650 seconds (that's what it said when it was done).

I don't know what to make of what happened.

I haven't tried the other macros, yet.

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Macros don't work

Post by Kino » 2010-12-29 05:30:39

Windsor wrote:3. It took 650 seconds (that's what it said when it was done).
I’m very sorry to be too slow in reply. That’s my macro and I reproduced the problem. I seem to have posted a buggy macro as a revised version. I think I corrected it. Please try this one (macro file attached below) which finishes to run in 16 seconds on Nisus Macro Reference.zrtf.
CompleteWordList_nwm.zip
(5.54 KiB) Downloaded 310 times

Code: Select all

### Complete Word List Macro (rev. 3) ###

# Written for Windsor.

# A new macro, let's call it Complete List, where the macro will be able to:
# a. list every word (case sensitive)
# b. list the number of frequency next to the word (italic style)
# c. list the page number next to the frequency number (plain style)
# If there are more than one frequency in a given page, let the number of frequency show and the page number to follow, for example: - California, 6–4,8,9,9,11,12.
# The dash between the frequency and the page number is "n-dash" [$freqSep], so the processor won't hyphenate.

# Changes:
# - When the same word appears multiple times in the same page, it will be noted as pageNumber(numberOfCoccurences), e.g. 23(7), where “(“ and “)” are defined by $openingFreq and $closingFreq.
# - For a page number in note text, “n“ ($noteSuffix) will be appended to it, e.g. 23n.
# - Words in Comments, Headers and Footers are ignored.

$shortestWordLength = 3
$caseSensitive = true  # set it to false if case-insensitive is preferable
$prefix = Cast to String '- '
$entrySep = Cast to String ', '
$freqSep = Cast to String '–'  # en-dash
$pageNumSep = Cast to String ','
$noteSuffix = Cast to String 'n'
$openingFreq = Cast to String '('
$closingFreq = Cast to String ')'
$suffix = Cast to String '.'
$debugEnabled = false

Require Pro Version 1.3
Debug.setCodeProfilingEnabled $debugEnabled

$doc = Document.active
if $doc == undefined
	exit  # exit silently if there is no open doucment
end

if $shortestWordLength < 2
	$findExp = '\b\p{L}(?:[-\'\x{2019}\x{559}-\x{55F}\p{L}]*\p{L})?\b'
else
	$SWL = $shortestWordLength - 2
	$findExp = '(?=\p{L}(?<w>[-\'\x{2019}\x{55A}-\x{55F}\p{L}]){' & $SWL
	$findExp &= ',}\p{L})\b\p{L}(?:\g<w>*\p{L})?'
end

$sels = $doc.text.findAll $findExp, 'Ew', '-amn'  # find in the main body and notes only

$data = Hash.new

foreach $sel in $sels
	$word = $sel.substring
	if $caseSensitive == false
		$word = $word.textByLowercasing
	end
	if $data{$word} == undefined
		$data{$word} = Hash.new
	end
	$pageNum = $sel.text.pageNumberAtIndex $sel.location
	$where = $sel.text.documentContentType
	if $where == 'table'
		$sel.length = 0
		$doc.setSelection $sel
		$where = $doc.tableSelection.table.enclosingText.documentContentType
	end
	if $where != 'body'
		$pageNum &= $noteSuffix
	end
	$data{$word}{$pageNum} += 1
end

$words = $data.keys
$words.sort 'li'  # l: localized (sort order chosen in Intl Pref pane) and i: case-insensitive
$output = Array.new

foreach $word in $words
	$outputTemp = $prefix & $word
	$outputTemp &= $entrySep
	$c = 0
	$pages = $data{$word}.keys
	$pages.sort
	$pageTemp = Array.new
	foreach $page in $pages
		$count = $data{$word}{$page}
		$c += $count
		if $count > 1
			$page &= $openingFreq & $count
			$page &= $closingFreq
		end
		$pageTemp.appendValue $page
	end
	if $c > 1
		$outputTemp &= $c & $freqSep
	end
	$outputTemp &= $pageTemp.join($pageNumSep) & $suffix
	$output.appendValue $outputTemp
end

$LF = Text.newWithCharacter 0x000A
$output = $output.join $LF

$WordList = Document.newWithText $output
$WordList.clearAndDisableUndoHistory

$findFreq = '[0-9]+(?=\Q'
$findFreq &= $freqSep & '\E)'
$numFound = Find All $findFreq, 'E'

if $numFound
	Menu ':Format:Italic'
end

Select Document Start

### end of macro ###
I don’t remember well the past discussion with you. So perhaps I misunderstand your needs. Please don’t hesitate to tell me if you find any inconvenience in it, with some examples for issues related to Armenian.

Sorry, again,

Kino

Windsor
Posts: 46
Joined: 2008-04-28 22:10:11
Contact:

Re: Macros don't work

Post by Windsor » 2010-12-29 18:14:02

Dear Kino,

Thank you for the post.

I realized one thing when I succeeded in using the macro, not this last one, I haven't downloaded your new one yet. The one thing was, whenever I have used soft-hyphen, the macro split the words, and in the list you could see half (or one third) of the word somewhere, and the rest somewhere else, according to the alphabetical order.

Before I download your newly posted macro, can you look at it and see if it will bypass the soft-hyphen and see the word as one word?

Thanks,
Windsor

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Macros don't work

Post by Kino » 2010-12-29 20:19:40

Ah, soft hyphen! I did not think of it. So here is yet another version which processes words containing soft hyphen and other few special characters correctly. It is a bit slower for it executes transliterateInRange commands against every and each word.
CompleteWordList_nwm.zip
(5.68 KiB) Downloaded 291 times
And...
I haven't tried the other macros, yet.
I think other macros are OK. The problem you reported in your first message is not caused by a difference between Tiger and Snow Leopard but by a bug(s) in that particular version of Complete Word List macro.

Kino

Code: Select all

### Complete Word List Macro (rev. 4) ###

# Written for Windsor.

# A new macro, let's call it Complete List, where the macro will be able to:
# a. list every word (case sensitive)
# b. list the number of frequency next to the word (italic style)
# c. list the page number next to the frequency number (plain style)
# If there are more than one frequency in a given page, let the number of frequency show
# and the page number to follow, for example: - California, 6–4,8,9,9,11,12.
# The dash between the frequency and the page number is "n-dash" [$freqSep],
# so the processor won't hyphenate.

# Changes:
# - When the same word appears multiple times in the same page, it will be noted
#   as pageNumber(numberOfCoccurences), e.g. 23(7), where “(“ and “)” are defined
#   by $openingFreq and $closingFreq.
# - For a page number in note text, “n“ ($noteSuffix) will be appended to it, e.g. 23n.
# - Words in Comments, Headers and Footers are ignored.
# - Words containing U+00AD (soft hyphen), U+0640 (tatweel),
#   U+200D (zero width joiner) are processed as they should.

$shortestWordLength = 3
$caseSensitive = true  # set it to false if case-insensitive is preferable
$prefix = Cast to String '- '
$entrySep = Cast to String ', '
$freqSep = Cast to String '–'  # en-dash
$pageNumSep = Cast to String ','
$noteSuffix = Cast to String 'n'
$openingFreq = Cast to String '('
$closingFreq = Cast to String ')'
$suffix = Cast to String '.'
$debugEnabled = false

Require Pro Version 1.3
Debug.setCodeProfilingEnabled $debugEnabled

$doc = Document.active
if $doc == undefined
	exit  # exit silently if there is no open doucment
end

if $shortestWordLength < 2
	$findExp = '\b\p{L}(?:[-\'\x{2019}\x{559}-\x{55F}\p{L}\x{AD}\x{200D}]*\p{L})?\b'
else
	$SWL = $shortestWordLength - 2
	$findExp = '(?=\p{L}(?<w>[-\'\x{2019}\x{55A}-\x{55F}\p{L}\x{AD}\x{200D}]){' & $SWL
	$findExp &= ',}\p{L})\b\p{L}(?:\g<w>*\p{L})?'
end

$sels = $doc.text.findAll $findExp, 'Ew', '-amn'  # find in the main body and notes only

$data = Hash.new
$spChars = Hash.new (0x00AD, '', 0x0640, '', 0x200D, '') # soft hyphen, tatweel, zero width joiner

foreach $sel in $sels
	$word = $sel.substring
	$range = Range.new 0, $word.length
	$word.transliterateInRange $range, $spChars
	if $caseSensitive == false
		$word = $word.textByLowercasing
	end
	if $data{$word} == undefined
		$data{$word} = Hash.new
	end
	$pageNum = $sel.text.pageNumberAtIndex $sel.location
	$where = $sel.text.documentContentType
	if $where == 'table'
		$sel.length = 0
		$doc.setSelection $sel
		$where = $doc.tableSelection.table.enclosingText.documentContentType
	end
	if $where != 'body'
		$pageNum &= $noteSuffix
	end
	$data{$word}{$pageNum} += 1
end

$words = $data.keys
$words.sort 'li'  # l: localized (sort order chosen in Intl Pref pane) and i: case-insensitive
$output = Array.new

foreach $word in $words
	$outputTemp = $prefix & $word
	$outputTemp &= $entrySep
	$c = 0
	$pages = $data{$word}.keys
	$pages.sort
	$pageTemp = Array.new
	foreach $page in $pages
		$count = $data{$word}{$page}
		$c += $count
		if $count > 1
			$page &= $openingFreq & $count
			$page &= $closingFreq
		end
		$pageTemp.appendValue $page
	end
	if $c > 1
		$outputTemp &= $c & $freqSep
	end
	$outputTemp &= $pageTemp.join($pageNumSep) & $suffix
	$output.appendValue $outputTemp
end

$LF = Text.newWithCharacter 0x000A
$output = $output.join $LF

$WordList = Document.newWithText $output
$WordList.clearAndDisableUndoHistory

$findFreq = '[0-9]+(?=\Q'
$findFreq &= $freqSep & '\E)'
$numFound = Find All $findFreq, 'E'

if $numFound
	Menu ':Format:Italic'
end

Select Document Start

### end of macro ###
Edit: Changed $debugEnabled = true to $debugEnabled = false and replaced the attached macro file.
Last edited by Kino on 2010-12-29 21:23:09, edited 1 time in total.

Windsor
Posts: 46
Joined: 2008-04-28 22:10:11
Contact:

Re: Macros don't work

Post by Windsor » 2010-12-29 20:50:43

thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you, thank you.

Another page is being made by the macro where every step taken is being reported. I think, I can delete it very easily by just closing it without saving it.

and this is the first three lines of the report:

Total macro elapsed time: 139.5 seconds
Total profiled execution time: 71.7 seconds
The following lists the percent of profiled time spent on each line:

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Macros don't work

Post by Kino » 2010-12-29 21:27:58

Another page is being made by the macro where every step taken is being reported.
Ah, sorry. I forgot to change $debugEnabled = true to $debugEnabled = false. I enabled this option while testing the new version of the macro. I corrected it in my previous posting and updated the attached macro file.

Also...
1. I noticed the logo of those macros were blank.
That is due to a change in OS X. If you still have macro files having a blank icon, I think running the following macro will restore the original icon by setting appropriate Type and Creator to them.
RestoreMacroFileIcon_nwm.zip
(4.91 KiB) Downloaded 287 times
Kino

Code: Select all

### Restore Macro File Icon ###

# Something close to
# find ~/Library/Application\ Support/Nisus\ Writer/Macros -name "*.nwm" -print0 | xargs -0 SetFile -c 'NISX' -t 'RTF '

Require Pro Version 1.3
Debug.setCodeProfilingEnabled false

$macrosFolder = User Property 'macros folder path'
$files = Array.new

$fileNames = File.namesInFolderAtPath $macrosFolder
foreach $fileName in $fileNames
	$filePath = $macrosFolder.filePathByAppendingComponent $fileName
	if File.isLinkAtPath $filePath
		$filePath = File.resolveLinkAtPath $filePath
	end
	$files.appendValue $filePath
end

foreach $i, $file in reversed $files
	if File.isFolderAtPath $file
		$fileNames = File.namesInFolderAtPath $file
		foreach $fileName in $fileNames
			$filePath = $file.filePathByAppendingComponent $fileName
			if File.isLinkAtPath $filePath
				$filePath = File.resolveLinkAtPath $filePath
			end
			$isFolder = File.isFolderAtPath $filePath
			if ! $isFolder
				$files.appendValue $filePath
			end
		end
		$files.removeValueAtIndex $i
	end
end

foreach $i, $file in reversed $files
	if $file.filePathExtension != 'nwm'
		$files.removeValueAtIndex $i
	else
		$fileInfo = File.infoAtPath $file
		if $fileInfo{'hfsCreator'} == 'NISX'
			if $fileInfo{'hfsType'} == 'RTF '
				$files.removeValueAtIndex $i
			end
		end
	end
end

if ! $files.count
	exit 'All macro files have proper Type/Creator, exit...'
end

$prefer32bit = undefined
Set Exported Perl Variables 'prefer32bit'
begin Perl
	$prefer32bit = `defaults read com.apple.versioner.perl Prefer-32-Bit 2>/dev/null`;
	chomp $prefer32bit;
	if ( $prefer32bit != 1 ) {
		`defaults write com.apple.versioner.perl Prefer-32-Bit -bool yes`;
	};
end

Set Exported Perl Variables 'prefer32bit', 'files'
begin Perl
	use MacPerl;
	foreach $file (@files) {
#		`SetFile -c 'NISX' -t 'RTF ' "$file"`;  # require SetFile in an executable path
		MacPerl::SetFileInfo ('NISX','RTF ',$file);
	}
	if ( $prefer32bit eq '' ) {
		`defaults delete com.apple.versioner.perl Prefer-32-Bit`;
	} elsif ( $prefer32bit eq '0' ) {
		`defaults write com.apple.versioner.perl Prefer-32-Bit -bool no`;
	};
end

### end of macro ###
Edit: Cleaned up the code and updated the attached macro file.

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Macros don't work

Post by Kino » 2011-05-19 09:26:54

Dear Windsor,

The macro will not work properly in NWP 2.0 due to a change in menu command paths. Here is a fixed version. I just replaced

Code: Select all

Menu ':Format:Italic'
near the end of the macro with

Code: Select all

Menu ':Format:Font Face:Italic'
CompleteWordList_20110520_nwm.zip
(5.65 KiB) Downloaded 340 times

Windsor
Posts: 46
Joined: 2008-04-28 22:10:11
Contact:

Re: Macros don't work

Post by Windsor » 2011-05-19 09:58:20

Thanks Kino, very kind of you.
Windsor

Post Reply