Part of Nobumi Iyanaga's website. n-iyanag@ppp.bekkoame.ne.jp. 8/16/06.

logo picture

Export Classic Nisus Writer Glossaries and Global Replace in NWE

Nobumi Iyanaga
2006-08-04
v. 0.75 2006-08-16

Introduction

I personally never used very much Classic Nisus Writer's glossary feature, but I recognize that it can be very useful for some people.

The new Nisus Writer Express has not yet a similar functionality. Instead, it has the "QuickFix" feature, which may be used as a kind of glossary; but it doesn't support styled text, nor does it support multi-line expanded words. But it is better than nothing.

There are also some system wide utilities specialized to enter words using abbreviations, for example Typinator, TypeIt4Me or Textpander (which became a shareware program named TextExpander). I for myself use Textpander, which was a freeware, and supports styled text as well as pictures.

It seems that there are people who would like to use their Classic NW glossary files in OS X applications, especially in NWE. Borrwoing from an idea of, and codes written by Kino, I could implement a set of scripts/macros which can achieve this. Note that it is impossible to specify the fonts used in the expanded words... The process may seem not VERY easy, but I think it would help people wanting to use the data they accumulated in old days.

The process of exporting a Classic Nisus Writer glossary file can be different depending on its contents and the way the user would like to use them. There are two points to be considered:

  1. Does the glossary file contain non MacRoman characters (in abbreviations and/or in expanded words) [e.g. Japanese, Chinese, etc.]?
  2. Are the style attributes of expanded words crucial for you?

If you say "yes" to one or both of these questions, you will have to follow the "complicated way" (below A); if you say "No" to these questions, you will follow the "easier way" (below B).

New in v. 0.75: After having released this set of scripts/macros, a user (Dan Bensky) found a problem in the process of exporting a long Classic Nisus Writer glossary file (with more than 255 entries). I could find the culprit, and fix it. But as Classic Nisus Writer macros are not very robust, when dealing with a long document, the application tends to crash. To avoid this problem, I made another version of ExportNWGlossary_StyledText.app, named "ExportNWGlossary_StyledText_long.app": this droplet stops after having open the exported file "[your_glossary_file_name]_abbr" in Classic Nisus Writer; you will have to execute the macros "ExpandAllAbbrev" and "SetStyleTags" yourself manually. On the other hand, I added two new macros to the Classic Nisus Writer macro file "ExportGlossaryMacro"; they may be used to add tags to colored texts and texts marked for "Table of Contents" and "Index". I added also a new macro for Nisus Writer Express, "color_charstyle_tags.pl", which will convert color tags and character style tags into "real" styles in Nisus Writer Express rtf files.

On the other hand, there is a new good news: TextExpander, v. 1.4 and later, a shareware of $29, can now import comma or tab delimited text file, or rtf file, or rtfd file as its snippets. With this feature, you will be able to export Classic Nisus Writer glossary items in a styled text file, convert it to an rtf file, and import its contents as TextExpander snippets. Please see below for details.

How to export a Classic Nisus Writer glossary file

As noted above, there are two different ways to export a Classic NW glossary file; but whatever the way you will follow, there are two things that you have to do before: that is:
  1. Make a copy of the glossary file to be exported, and put it on your Desktop (Classic Nisus Writer glossary files are in your Nisus Writer Tools:Glossaries:" folder).
  2. Open your /Users/[your_account]/Application Support/Nisus Writer/ folder, and create there a new folder named "macro_helper" (if you don't like to do that yourself, I prepared an AppleScript application named "ExportNWGlossary_install.app"; it will do the necessary for you...: see below how it will work).

A. For people who used non MacRoman characters in their glossary file, or for people for whom the style attributes of expanded words are important

Note that with the new "ExportNWGlossary_StyledText_long.app", you have the choice to use either "ExportNWGlossary_StyledText.app" or "ExportNWGlossary_StyledText_long.app". Use the latter, if your glossary has many entries. The process will be different at the Step 6 below.

  1. Put the AppleScript droplet named "ExportNWGlossary_StyledText.app" (or "ExportNWGlossary_StyledText_long.app") on your Desktop;
  2. Put the macro file named "ExportGlossaryMacro" in your "Nisus Writer Tools:Macros:" folder.
  3. Be sure that the glossary file that you would like to export is in your "Nisus Writer Tools:Glossaries:" folder.
  4. Launch your copy of Classic Nisus Writer.

  5. Now, the process begins: Drag & drop the copy of your glossary file to be exported (which is on your Desktop) on the AppleScript droplet named "ExportNWGlossary_StyledText.app" (or "ExportNWGlossary_StyledText_long.app").
  6. A: if you use "ExportNWGlossary_StyledText.app": After some seconds, Classic Nisus Writer will open a new file named "[your_glossary_file_name]_abbr" and the macro named "ExpandAllAbbrev" and the macro "SetStyleTags" will run (these macros are in the macro file ExportGlossaryMacro). When the script ends, you will see this message: "Now, please examine and edit the file; when you are satisfied, open it with Nisus Writer Express and use the macro "Add_to_QyuckFix" or "Add_to_Textpander" to use the glossary in your OS X environment...".

    B: if you use "ExportNWGlossary_StyledText_long.app": After some seconds, Classic Nisus Writer will open a new file named "[your_glossary_file_name]_abbr"; when the script stops, you will see the message: "Now, please run the macro ExpandAllAbbrev, and run the macro SetStyleTags. If necessary, run the macro z_color_tags and/or z_Index_toc_tags. Save the file before running any macro. Now, examine and edit the file; when you are satisfied, open it with Nisus Writer Express and use the macro Add_to_QyuckFix or Add_to_Textpander to use the glossary in your OS X environment..."

    What is important here is to save the file as often as possible.
    Note that "z_color_tags" supports only colors red, blue, green and cyan. If your expanded words have other colors than these four colors, it is better to not use this macro.
    The macro "z_Index_toc_tags" adds tags "<idx>xxx</idx>" and "<toc>xxx</toc>" for expanded texts marked for Index and Table of Contents.
    Note that Nisus Writer Express still doesn't support Index and Table of Contents features -- so these tags are not useful for now; however, after importing the document into Nisus Writer Express, if you run the macro "color_charstyle_tags", the texts between these tags will have character styles named "idx" or "toc". These character styles may be useful when Nisus Writer Express will support Index and Table of Contents features. -- But note that the macro "color_charstyle_tags" is still experimental; they may not work as expected. So, perhaps it is better to not use the macros "z_color_tags" and "z_Index_toc_tags"...

    The following remark is valid for users who have chosen either "ExportNWGlossary_StyledText.app" or "ExportNWGlossary_StyledText_long.app":

    Even if the abbreviations/expanded words contain non MacRoman characters, they should display correctly -- but if there are some garbled characters, you will have to correct them manually. You should see a screen like this:

    abbrev_exp picture

    As this example shows, each abbrev / expanded words pair occupies one line, and they are separated by a tab. Expanded word in italic are enclosed between the tags "<i>" and "</i>"; other styles supported are bold, superscript and subscript. Note that if your expanded words use the font "Any Font", there may be incorrect style tags. Note also that you cannot specify the font of the expanded words (this means that my scripts/macros set does not support expanded words in special encoding fonts, for example fonts for transliteration of Asian languages...).

    Examine this file attentively. There may be useless abbrev / expanded words pairs (in the example above, "CB", which expands into "Show Clipboard" was useful only for writing macros for Classic Nisus Writer; in the new Nisus Writer Express, it is of no use, etc.). You will have another occasion later to examine the abbrev / expanded words pairs.

    If you are satisfied, close that window. The original file is in the /tmp/ folder. This folder is usually invisible, but you can open it with the Services menu: write /tmp/ in a new window, for example in Nisus Writer Express; select it; and from the Services menu, choose Finder > Reveal: you will find your original file there. Another, edited copy of the file is on your Desktop. -- You should keep these files somewhere...

  7. Open the newly created file on your Desktop with Nisus Writer Express. Now, you can examine again the file, and choose if you want to use its contents for QuickFix in Nisus Writer Express or for Textpander. Note that Textpander is not a good choice for styled text expanded words (I am unable to implement the needed code in order to registrate styled text into Textpander snippets...).

B. For people who use only MacRoman characters in Classic Nisus Writer glossary files, and who don't care about the style attributes of expanded words

  1. Put the AppleScript droplet named "ExportNWGlossary_MacRomn.app" on your Desktop;
  2. Drag & drop the copy of your glossary file to be exported (which is on your Desktop) on the AppleScript droplet named "ExportNWGlossary_MacRomn.app".

  3. After some seconds, a new file will open in Nisus Writer Express. It's name is [your_glossary_file_name]_abbr.txt, and it is on your Desktop. Examine and edit this file...

How to add glossary items into a Nisus Writer Express "QuickFix" "typo / fix" list

As Nisus Writer Express Help states, "The QuickFix preference of Nisus Writer Express can fix your typos as you type", and it is "language specific".

The "languages setting files" for Nisus Writer Express are in your /Users/[your_account]/Library/Application Support/Nisus Writer/Languages/ folder. There are files named for example "English - US.nlang" or "French.nlang", with the extension ".nlang". It is possible to use one of the existent .nlang files, but I would strongly recommend to "Custom Language" setting file. If you choose an existent .nlang file, there may be an advantage and a drawback. The advantage is that to use your glossary items, you don't need to change the Language setting each time; but the drawback is that an existing language file containing already many "typo / fix" pairs, the "auto-correction" feature may interfere your natural typing habit (and of course, to use the glossary feature, you have to set the "auto-correction" feature ON). More importantly, my script may break an existing .nlang file; this must be avoided!

If you choose to create a "Custom Language", you will have to change the Language setting each time you want to use the glossary expansion, but in fact, you can keep that Language setting always as well -- you will be able to use the Spell Checker (as well as the Thesaurus if you set it to English). So, I would recommend to create a new "Custom Language" for your glossary expansion feature, especially if you want to use it often.

To create a new "Custom Language", open Preferences > Languages, and press the + button at the bottom of the left side list view. You will enter a name for this "language" (this may be for example "glossary1"); set the Based on, Spelling, etc. options as you want. When you have done, close the Preferences window.

Now, some steps are necessary to import your Classic Nisus Writer glossary items into a Nisus Writer Express language file's "typo / fix" list:

  1. Put the AppleScript script named "Add_to_QuickFix.scpt" into your /Users/[your_account]/Library/Application Support/Nisus Writer/Macros/ folder.
  2. Put the Perl script named "add_to_quickfix.pl" into your /Users/[your_account]/Library/Application Support/Nisus Writer/macro_helper/ folder (if you have not yet created this folder, create it now...).

  3. Open your [your_glossary_file_name]_abbr.txt file, or your [your_glossary_file_name]_abbr file in Nisus Writer Express (if it is the latter file, Nisus Writer Express will open it in an Untitled window). Examine it again attentively.
    • Aren't there any multi-line expanded words?
    • Isn't there any control character? (Macro symboles in Classic Nisus Writer glossary files are control characters...)
    • Nisus Writer Express QuickFix allows non ASCII characters as abbreviations; but using a Japanese string for example as an abbreviation is not very clever; to "trigger" the expansion, you must change the input method, to type a space...
    • Are all the abbreviations / expanded words pairs good for Nisus Writer Express QuickFix typo / fix pairs? Consider the fact that the "trigger" for expanding abbreviations in Classic Nisus Writer, and the one for "fixing typos" in Nisus Writer Express are different...

  4. If everything is OK, add at the top of the file a new line, and type there the name of the Language file to which you want to add your new abbreviations / expanded words pairs: that may be for example glossary1.nlang (you may omit the extension ".nlang"). Caveat: don't take the language name as it appears in the Preferences window, but use the file name in your /Users/[your_account]/Library/Application Support/Nisus Writer/Language/ folder (thus, not English (U.S.), but English - US.nlang). -- The first line of the file must not contain any other character.

    You can of course write from scratch similar pairs of abbreviations /expanded words, and add them in a ".nlang" file of your preference.

  5. When this is done, select all the text, and choose from the Macros menu the menu item named "Add_to_QuickFix". After some seconds, a dialog will appear, saying:

    ...Now, your original Language file is saved on your Desktop, and a new [your_language].nlang file is generated in your /Users/[your_account]/Library/Application Support/Nisus Writer/Languages/ folder.

    Please quit Nisus Writer Express once, then...

    Test the new [your_language].nlang file. If something is wrong, replace the new file with the original one.

    If everything is OK, you can trash your original [your_language].nlang file....

    Follow these instructions carefully.

    Set your Language to the language in which you added your glossary items; you should be now able to use the abbreviations which will expand automatically into the expanded words. If this does not work, examine the setting of your "Language"'s QuickFix in Preferences > QuickFix: the checkbox Fix typos must be checked!

  6. If you have expanded words which are enclosed between style tags such as "<i>" and "</i>", you will have to do two other steps to get them in the expected styles:
    1. Put the Perl script named "tag2style.pl" in your /Users/[your_account]/Library/Application Support/Nisus Writer/Macros/ folder.
    2. After having edited your documemt. when you have finished all your editing, choose the macro named "tag2style" from the Macros menu. A new window will appear, in which all the words enclosed between style tags -- for Italic, Bold, Superscript and Subscript -- will be displayed in the desired styles.

  7. If you have expanded words which are enclosed between color tags such as "<red>" and "</red>", or character style tags such as "<idx>" and "</idx>"you will have to do run the macro named "color_charstyle_tags": please note that this macro supports only the colors, red, blue, green and cyan. If your document uses other colors, this macro will mess them up -- so you must not use it in such a case.

    As to character style, any tag (other than color tags and style tags such as <i> and </i>) can be used. But if the document has already character styles, the macro may not work as expected. Anyway, please note that this macro is still experimental. Use it with caution!

How to add glossary items into Textpander's "snippets" list

Textpander's "snippets" are stored in the file /Users/[your_account]/Library/Application Support/Textpander/Settings.textpander. It is a .plist file which can be edited with Property List Editor.

To add glossary items into Textpander's "snippets" list, you will do the following steps:

  1. Put the AppleScript script named "Add_to_Textpander.scpt" in your /Users/[your_account]/Library/Application Support/Nisus Writer/Macros/ folder.
  2. Put the Perl script named "add_to_textpander.pl" into your /Users/[your_account]/Library/Application Support/Nisus Writer/macro_helper/ folder (if you have not yet created this folder, create it now...).

  3. Open your [your_glossary_file_name]_abbr.txt file, or your [your_glossary_file_name]_abbr file in Nisus Writer Express (if it is the latter file, Nisus Writer Express will open it in an Untitled window). Examine it again attentively.
    • Textpander allows multi-line expanded words.
    • Isn't there any control character? (Macro symboles in Classic Nisus Writer glossary files are control characters...)
    • Textpander seems to not allow a non ASCII character (or Japanese character) in an abbreviation...
    • Are all the expanded words without style tags? -- My scripts/macros set doesn't support styled text in Textpander. If you have style tags like "<i>" and "</i>" in your file, you must delete them all.
    • Are all the abbreviations / expanded words pairs good for Textpander snippets? Consider the fact that the "trigger" for expanding abbreviations in Classic Nisus Writer, and the one for snippet expanding in Textpander are different... By the way, Textpander has a very good Help which explains general rules as to how to set the abbreviations. This Help may be helpful for setting "typos / fix" pairs in Nisus Writer Express QuickFix as well.

  4. If everything is OK, add at the top of the file a new line, and type there one of the following words:
    • Require Matching Cases
    • Ignore Case
    • Adapt Content
    This will be the mode for all the abbreviations. For details about this expansion mode, please refer to Textpander Help. In fact, Textpander can define a mode different for each snippet, but in my script, this seemed too complicated. If you want, you will be able to set your mode for each of your snippets.

    The first line of the file must not contain anything other than one of these three words.

    You can of course write from scratch similar pairs of abbreviations /expanded words, and add them to Textpander snippets list.

  5. When this is done, select all the text, and choose from the Macros menu the menu item named "Add_to_Textpander". After some seconds, you will see the following message:
    Your original Settings.textpander file is saved on your Desktop, and a new Settings.textpander file is generated in your /Users/[your_account]/Library/Application Support/Textpander/ folder.

    Please open Textpander Preferences once, look at the snippet list, close it, and test the new snippets; if everything works as expected, you can trash the original file on your Desktop.

    If something goes wrong, replace the new file with the original one.

    Follow these instructions carefully.

Now, you should be able to use your glossary items in Textpander...

How to use Classic Nisus Writer glossary data in TextExpander

With TextExpander v. 1.4 and later, you can import comma or tab delimited text file, rtf file or rtfd as TextExpander snippets. This is much better than the other methods described above, since it does not overwrite property list files such as Settings.textpander or NWE's .nlang files.

There are two possibilities: use a non-formatted text file, or a formatted rtf file.

  1. To use a non-formatted text file, which is the simplest way, you will simply drag and drop your Classic Nisus Writer glossary file onto the droplet "ExportNWGlossary_MacRoman.app". Note that this supports only MacRoman encoded files. This will generate a file named "[your_glossary_file_name]_abbr.txt" on your Desktop. You will open it and edit it... When you are satisfied, you will import that file as TextExpander snippets.

  2. To use a formatted file, you will:
    • drag and drop your Classic Nisus Writer glossary file onto the droplet "ExportNWGlossary_StyledText_long.app" (regardless of the number of items in your glossary file);
    • after some seconds, Classic Nisus Writer will open a new file named "[your_glossary_file_name]_abbr"; run the Classic Nisus Writer macro named "ExpandAllAbbrev"; in principle, this should be enough to get a good formatted text. Delete every separator dash line between each pair of abbreviation / expanded words (you can use the PowerFind Pro: the Find expression is: "^\-+$\r", and leave the Replace box blanc; then press Replace All button); examine and edit this file (which is on your Desktop); when you are satisfied, save it.
    • open that file with Nisus Writer Express, and save it as an rtf file. You can use this file to import its contents as TextExpander snippets.

Nisus Writer Express Global Replace

Borrowing also from a script written by Kino, I wrote another little goody for Nisus Writer Express. This is a kind of "Global Find and Replace" function.

You create a text file in which you write your pairs of Find words and Replace words. You may have a file like this:


ul	upload
isn't	is not
abbr	abbreviation
app	application
apps	applications
MS	Microsoft
SM	sadomasochism
NWE	Nisus Writer Express
mahuang	Ephedrae Herba (<i>má huáng</i>)
dk	<i>ḍākinī</i>

Each pair occupes a line, and the Find word and the Replace word are separated by a tab.

You will save this file as UTF8 text file, named "glossary.txt" in your /Users/[your_account]/Application Support/Nisus Writer/macro_helper/ folder.

You will put the Perl script named "global_replace.pl" in your /Users/[your_account]/Application Support/Nisus Writer/Macros/ folder.

When you have finished editing a document, in which you will have used these Find words (e.g. abbreviations), you will run the macro named "global_replace" from the Macros menu; all the Find words will be replaced with the paired Replace words.

You can also specify the style attributes of the Replace words, using the style tags:

<i> and </i>
<b> and </b>
<sup> and </sup>
<sub> and </sub>

Note that all the Find words must be in ASCII characters, while the Replace words can contain any Unicode characters.

Installer

I added an AppleScript application named "ExportNWGlossary_Installer.app". It MUST be in the same folder as all the other scripts/macros.

Double-clicking on its icon, you will put:

  1. "ExportNWGlossary_StyledText.app" on your Desktop
  2. "ExportNWGlossary_StyledText_long.app" on your Desktop
  3. "ExportNWGlossary_MacRoman.app" on your Desktop

  4. "Add_to_QuickFix.scpt" in your /Users/[your_account]/Application Support/Nisus Writer/Macros/ folder;
  5. "Add_to_Textpander.scpt" in your /Users/[your_account]/Application Support/Nisus Writer/Macros/ folder;
  6. "color_charstyle_tags.pl" in your /Users/[your_account]/Application Support/Nisus Writer/Macros/ folder;
  7. "global_replace.pl" in your /Users/[your_account]/Application Support/Nisus Writer/Macros/ folder;
  8. "tag2style.pl" in your /Users/[your_account]/Application Support/Nisus Writer/Macros/ folder;

  9. if the folder /Users/[your_account]/Application Support/Nisus Writer/macro_helper/ doesn't exist, it will create one;

    Then it will put:

  10. "add_to_quickfix.pl" in your /Users/[your_account]/Application Support/Nisus Writer/macro_helper/;
  11. "add_to_textpander.pl" in your /Users/[your_account]/Application Support/Nisus Writer/macro_helper/;
  12. "glossary.txt" in your your /Users/[your_account]/Application Support/Nisus Writer/macro_helper/.

    Finally,

  13. It will open the ReadMe file in Nisus Writer Express,
  14. and generate a log file on your Desktop.

Note that it will NOT put the Classic Nisus Writer macro "ExportGlossaryMacro" in your "Nisus Writer Tools:Macros:" folder; you will have to put it there manually.


Package contents


ExportGlossaryMacro
ExportNWGlossary_MacRoman.app
ExportNWGlossary_StyledText.app
ExportNWGlossary_StyledText_long.app
ExportNWGlossary_install.app
Macros/	--> Files to be put in /Users/[your_account]/Application Support/Nisus Writer/Macros/
	Add_to_QuickFix.scpt
	Add_to_Textpander.scpt
	color_charstyle_tags.pl
	global_replace.pl
	tag2style.pl
macro_helper/	--> Files to be put in /Users/[your_account]/Application Support/Nisus Writer/macro_helper/
	add_to_quickfix.pl
	add_to_textpander.pl
	glossary.txt
ReadMe.rtfd
scripts:	--> scripts used in AppleScript application bundles
	ExtractABBR(StyledText).pl
	ExtractABBR(macRoman).pl
	exportNWGlossary_install.pl


Download

Please download the package from this link (357K to download).

Please use these scripts/macros with caution. They may contain bugs!!

I would appreciate any feedback. Thank you in advance.


Go to Nisus Macros and Nisus/Frontier combo page
Go to NI Home Page


Mail to Nobumi Iyanaga


frontierlogo picture

This page was last built with Frontier on a Macintosh on Wed, Aug 16, 2006 at 7:01:42 PM. Thanks for checking it out! Nobumi Iyanaga