Page 1 of 1

Keyboard/Language

Posted: 2009-07-20 05:36:01
by jb
Hi
I have the keyboard shortcut Command-Space Bar set to switch to the most recent previous keyboard layout used ('Select Previous Input Source' in System Preferences). This is great because it allows me to move easily back and forth between two keyboards. But I prefer to use these two keyboards with two different fonts: Keyboard 1 with Font A; Keyboard 2 with Font B.

Is there a way to set Nisus to assign a particular language to a particular keyboard? Or at least to toggle between two? In other words, I'd like to be able to use a single keyboard shortcut to switch BOTH keyboard and language (which brings along font).

Sorry if I've missed this somewhere.

Re: Keyboard/Language

Posted: 2009-07-20 06:49:58
by Kino
1. Enable languages you need in “Preferences - Language” and set “Switch Keyboard” to “Switch to chosen keyboard” or “Switch to last used keyboard”.

2. Install this macro and change the values of $langName1 and $langName2 — very first commands of the macro — so that they match your language settings.

3. Assign a shortcut to the macro in “Preferences - Menu Keys”. Unfortunately, you cannot use command-space or command-option-space which are taken by Apple.

Hopefully this will solve your problem. My problem is that I have to deal with three keyboard layouts and it is hard for me to use different shortcuts in Nisus Writer Pro and in other applications. I'd like to have the automatic font change à la Word or OpenOffice.

Code: Select all

$langName1 = 'French'  # Name of the language shown under Format:Language
$langName2 = 'Arabic'  # Name of the language shown under Format:Language
$lang1 = $lang2 = undefined
$languages = Language.enabledLanguages
foreach $language in $languages
	if $language.name == $langName1
		$lang1 = $language
	elsif $language.name == $langName2
		$lang2 = $language
	end
end

$sel = TextSelection.active
if $sel == undefined
	exit # Either no document is open or the focuce is not in the text field
end
$lang = $sel.displayTypingAttributes.language

if $lang != $lang1
	$lang1.apply
else
	$lang2.apply
end

Re: Keyboard/Language

Posted: 2009-07-20 07:03:02
by jb
Dear Kino
This is quite a welcome back! I see you are still the generous magician. Thank you.

Unfortunately, I get this Error message (I named macro 'LanguageKeyboard'):

There was an error on line 20 in the macro "LanguageKeyboard".

The "apply" property requires an object, instead found "undefined" from "$lang1"

?

Thanks again,
James

Re: Keyboard/Language

Posted: 2009-07-20 07:05:52
by jb
Sorry !

I had forgotten something in the name of the Languge...

all seems well.

Re: Keyboard/Language

Posted: 2009-07-21 03:13:07
by Kino
No, no. It’s me who have ot say sorry. That error was caused by my stupid coding. It is unnecessary for macros for such a purpose to know the language names exactly. And you may be forced to configure $langName1 and $langName2 again when you change the language settings. That is tedious. The following would be better:

Code: Select all

### Switch to the Next laguage ###

Require Pro Version 1.2

$sel = TextSelection.active
if $sel == undefined
	exit # either no document is open or the focuce is not in the text field
end

$currentLang = $sel.displayTypingAttributes.language
$languages = Language.enabledLanguages

$i = $languages.indexOfValue $currentLang
$i += 1
$languages[$i%$languages.count].apply
Some explanation. $sel.displayTypingAttributes.language returns the language object applied on the active selection which is most likely a zero-width caret. For such a macro, you cannot use displayAttributesAtIndex command because it fails when the caret (insertion point) is at the very end of the document. And this occurrs inevitably when you open a new and empty document window.

Language.enabledLanguages returns an array consisting of all languages you have enabled in Preferences - Languages. For example, when “English - US”, “Greek”, “Russian” and “Tech - Email” are enabled, they will be stored in $languages in the following manner:

Index 0: English - US
Index 1: Greek
Index 2: Russian
Index 3: Tech - Email

Then, if the current language is “Greek”, $languages.indexOfValue $currentLang returns “1”, that the next command $i += 1 will increase by 1.

When the current language is “Greek” (index 1), $languages[$i].apply is sufficient as the last command and “Russian” (index 2) will be applied by the macro. However, if the current language is “Tech - Email” (index 3), $languages[$i].apply fails because the index 4 does not exist. This is why the index is given by $i%$languages.count, i.e. the remainder of $i divided by the total number of enabled languages (“4%4 = 0” in this example).

For those who have enabled two languages, this macro is sufficient and it works as a toggle command. Those who have enabled more than two languages may want to have a macro which cycles languages in the reverse order too.

Code: Select all

Switch to the Previous laguage

Require Pro Version 1.2

$sel = TextSelection.active
if $sel == undefined
	exit # either no document is open or the focuce is not in the text field
end

$currentLang = $sel.displayTypingAttributes.language
$languages = Language.enabledLanguages

$i = $languages.indexOfValue $currentLang
$i += $languages.count - 1
$languages[$i%$languages.count].apply

Re: Keyboard/Language

Posted: 2009-07-24 21:49:57
by rwg
jb wrote:I have the keyboard shortcut Command-Space Bar set to switch to the most recent previous keyboard layout used ('Select Previous Input Source' in System Preferences). This is great because it allows me to move easily back and forth between two keyboards. But I prefer to use these two keyboards with two different fonts: Keyboard 1 with Font A; Keyboard 2 with Font B.
This has always been a stumbling block to my use of Nisus -- having to use two keyboard shortcuts to switch between two keyboards to which different fonts have been assigned. Kino's macro goes some way to solving the problem, but I still very much prefer Mellel's use of a main font and a secondary font, which gives the same functionality, but with the standard keyboard shortcut Command + Space.

Another related problem I have is that Nisus doesn't play nicely with my configuration of Spell Catcher. Spell Catcher allows one to set a keyboard layout of one's choice, which I have set to the keyboard layout I use for one of the two languages I want to use with Nisus. The problem is that whereas I want Nisus to switch to Spell Catcher with this particular keyboard layout selected, Nisus switches directly to the keyboard layout, and I then have to select Spell Catcher from the International menu and manually reselect the keyboard I want in order to achieve what I can do in Mellel by simply pressing Command + Space.

I suppose this is an inevitable consequence of the way in which Nisus handles languages, but if there is a solution, I would love to hear about it.

Rolf

Re: Keyboard/Language

Posted: 2010-08-06 11:07:20
by martin
A recent user request, and the macros Kino posted above, inspired me to write my own language cycling macros. The key difference is that the new macros will automatically guide the user to configure the list of languages to cycle between.

Unfortunately one still cannot use the Command + Space keyboard shortcut for the macros, because that shortcut is reserved by OSX.