Macros don't work
Macros don't work
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
thanx,
Windsor
Re: Macros don't work
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?
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
Re: Macros don't work
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
Thanx,
Windsor
Re: Macros don't work
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.
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.
Re: Macros don't work
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.Windsor wrote:3. It took 650 seconds (that's what it said when it was done).
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 ###
Sorry, again,
Kino
Re: Macros don't work
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
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
Re: Macros don't work
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.
Kino
Edit: Changed $debugEnabled = true to $debugEnabled = false and replaced the attached macro file.
And...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.I haven't tried the other macros, yet.
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 ###
Last edited by Kino on 2010-12-29 21:23:09, edited 1 time in total.
Re: Macros don't work
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:
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:
Re: Macros don't work
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.Another page is being made by the macro where every step taken is being reported.
Also...
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. Kino1. I noticed the logo of those macros were blank.
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 ###
Re: Macros don't work
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 replacednear the end of the macro with
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'
Code: Select all
Menu ':Format:Font Face:Italic'
Re: Macros don't work
Thanks Kino, very kind of you.
Windsor
Windsor