Selection of the input language from within a Nisus macro

Get help using and writing Nisus Writer Pro macros.
Post Reply
js
Posts: 229
Joined: 2007-04-12 14:59:36

Selection of the input language from within a Nisus macro

Post by js » 2008-08-17 01:53:31

Is it possible to change the selection of the input language from within a Nisus macro, like changing from English to French, or changing from English to a Two-Byte language and back?

If not, can you achieve that by calling System Events from inside a Nisus macro?

One practical goal is to make sure that either one-byte or two-byte input is on without having to look at the menu.

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

Re: Selection of the input language from within a Nisus macro

Post by Kino » 2008-08-17 05:34:00

js wrote:Is it possible to change the selection of the input language from within a Nisus macro, like changing from English to French,
Yes, you can just use a menu command:

Code: Select all

Menu ':Format:Language:French'
or changing from English to a Two-Byte language and back?
Perhaps you need something like this?

Code: Select all

 Require Application Version '3.1'
$doc = Document.active
$sel = $doc.textSelection
$text = $doc.textSelection.text
$index = $sel.location
$displayAttr = $text.displayAttributesAtIndex $index
$lang = $displayAttr.languageCode
if $lang == 'en_GB'
	Menu ':Format:Language:Japanese'
elsif $lang == 'ja'
	Menu ':Format:Language:English (British)'
end # do nothing for other languages
You'll get an error if the caret is at the very last of a text object because there is no following character there. That is true but does not match the real word processing: you can still change the language at such an insertion point.

js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: Selection of the input language from within a Nisus macro

Post by js » 2008-08-17 06:08:10

Thanks for your help. In fact this does not quite solve my problem: I do not want to change the fonts under the format menu. Their purpose is to let Nisus choose the proper dictionary. What I want to do is to select the input method. This is on an Apple menu on the right (not on a Nisus menu that is). If you change the input language there the keys of your keyboard are attributed differently, and in the case of two-byte languages like Chinese or Japanese there are also changes of a different nature. As these language input menus are under the control of the System rather than of Nisus,, I thought maybe it can be done by System commands.

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

Re: Selection of the input language from within a Nisus macro

Post by Kino » 2008-08-17 06:47:03

js wrote:What I want to do is to select the input method. This is on an Apple menu on the right (not on a Nisus menu that is). [...] As these language input menus are under the control of the System rather than of Nisus,, I thought maybe it can be done by System commands.
Ah, I undestand. So do you need something like OS 9's "synchronize keyboard layout and script"? If so, that is the feature or the behaviour I have requested repeatedly. Unfortunately NW Pro macro does not have the ability to detect the change of input method and to run a macro automatically.

To be exact, my feature request is [1] addition of commands such as "Select the previously selected language" and "Cycle language" and [2] ability to assign shortcuts "command-space" and "command-option-space" to those commands which will override system shortcuts of the same key combination. Then, I think, we can get back the easiness of multi-language wordprocessing à la NW Classic.

js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: Selection of the input language from within a Nisus macro

Post by js » 2008-08-17 07:25:59

Yes, that’s it. For anybody who uses a mixed environment the real solution should come from Apple: The Icon of the insertion should change according to the input you chose. Then you could work really fast. But go and tell them.
In the meantime a word processor like Nisus could probably do it within their environment, but same thing here: Very few people need it, and those who don’t might not realize how helpful this would be. Still I think it could be done on a macro level; I am just not very good at actually doing it.
The idea is this: Sometimes I would just like to start typing and be sure that I am in the good environment, f.e. in Japanese rather than English, or vice versa, without looking anywhere. What I have to do now is: 1. Look at the top Apple menu and discover the icon. 2. Manually change from one to the other, if necessary, through the keyboard or by pulling down a menu. Now if I could have a Nisus macro with a shortcut that is capable to execute a system call which choses item such and such (by name or maybe by position) of that language input menu then the problem would be solved. But I don’t know if this is possible.

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

Re: Selection of the input language from within a Nisus macro

Post by Kino » 2008-08-17 08:12:21

js wrote:The idea is this: Sometimes I would just like to start typing and be sure that I am in the good environment, f.e. in Japanese rather than English, or vice versa, without looking anywhere. What I have to do now is: 1. Look at the top Apple menu and discover the icon. 2. Manually change from one to the other, if necessary, through the keyboard or by pulling down a menu.
If you have defined languages with "Switch Keyboard" set to "Switch to chosen keyboard" in NW Pro's Languages Preferences, the process could be reduced to the selection of an appropriate language from the flag menu in the Statusbar, I think. Alternatively you can assign shortcuts to languages under Format:Language and use them to select a language. And it is not impossible to write macros for cycling and toggling languages to which you could assign shortcuts.

However, the problem is that NW Pro does not allow you to use command-space and command-option-space as menu keys in the Language Preferences (you could change the system shortcuts but I'm accustomed to them since OS 7.5). So you would be forced to use different shortcuts for the same or similar purpose in NW Pro and in all the other applications. That is confusing and barely user-friendly. This is why I requested the ability to use those key combinations as menu keys.

js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: Selection of the input language from within a Nisus macro

Post by js » 2008-08-17 10:27:28

If you have defined languages with "Switch Keyboard" set to "Switch to chosen keyboard" in NW Pro's Languages Preferences, the process could be reduced to the selection of an appropriate language from the flag menu in the Statusbar, I think. Alternatively you can assign shortcuts to languages under Format:Language and use them to select a language.
You are right; I did not think of this. Thank you. Inf fact a short delay seems to indicate the Nisus in this case does what I wanted to do in the Apple input scripts menu menu directly.

User avatar
martin
Official Nisus Person
Posts: 4361
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Selection of the input language from within a Nisus macro

Post by martin » 2008-08-18 15:10:15

Kino wrote:However, the problem is that NW Pro does not allow you to use command-space and command-option-space as menu keys in the Language Preferences
It's unlikely we'll be able to allow this. Last I checked OSX eats those keyboard shortcuts before NWP gets to see them at all.

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

Re: Selection of the input language from within a Nisus macro

Post by Kino » 2008-08-19 08:37:38

martin wrote:It's unlikely we'll be able to allow this. Last I checked OSX eats those keyboard shortcuts before NWP gets to see them at all.
Ah, that is a bad news. Thank you for checking for it anyway. But... but perhaps is it possible for NW Pro to detect the change of keyboard layout? OCSmartHacks' Keyboard Watcher does it* although I don't know if it can be achieved in a normal way. I don't know but if NW Pro can get the newly selected keyboard, somethin like "Switch to last used Language when keyboard changes" as a pref option will solve the problem. And this solution would be, in a sense, more natural. A keyboard layout can be used for multiple languages, though.
*http://www.ocs.cz/OCSmartHacks/PowerUser/PowerUser.html

Please note that people needing this kind of facility are not "very few" in countries whose language does not belong to the Roman script.

Thanks in advance ;-)

js
Posts: 229
Joined: 2007-04-12 14:59:36

Re: Selection of the input language from within a Nisus macro

Post by js » 2008-08-21 01:43:11

Please note that people needing this kind of facility are not "very few" in countries whose language does not belong to the Roman script.
This is maybe less clear than it seems to be: If a Chinese who writes in Chinese, (a two-byte script) wants to add some words in English, he does normally not switch to the English keyboard, but uses the letters of the alphabet integrated into his two-byte system (just as we normally do not switch to Greek for writing an alpha sign. The result is that normally such scripts are badly equipped to write a German umlaut, or French and Spanish accents and the like. But of course if these multi script usage would be well implemented, things might be different. I am convinced that a visual help in the caret would make a very big change here. To me, the problem seems less HOW to change from the one-byte font to the two-byte font or vice versa, but to know at all times what will happen when you press the key. Let's say you see a red cursor and immediately know: when I press the key I will see a Chinese character, rather than a letter of the alphabet: that would really make a difference. Which keyboard short cut is used to tell my Mac to go ahead, or to change to the other script seems not so important: You have to do it one way or the other. And Apple does allow you to chose the shortcut you prefer (Preferences:Keyboard shortcuts, Input selection. I can't really see why you would override these in Nisus if you can change them in the system). What really would make a change is to easily see whether you have to switch or not. I think if Nisus could implement a script sensitive cursor this would be an incredible help for anybody who needs fast text input in mixed one-byte two-byte text environment.

Post Reply