4 Replies Latest reply on Mar 10, 2014 10:16 AM by Nadav

    Changing English to Hebrew and vice versa

    Nadav

      Hi,

       

      I'm writing a math book in hebrew where the text is in hebrew but the numbers and variables are in english.

      I have a specific character type for english and another one for hebrew.

      When I'm typing the book I need to change from hebrew to english and vice versa all the time.

      Each such change require two operation: 1. chaging the character type (for which I have an easy keyboard shortcut) 2. Changing the keyboard to use Hebrew or English (using win7's shortcut - Shift + Alt).

      I would like to combine those two operation into one keyboard shortcut.

      As I see it I need to do one of the following:

      1. When Shift + Alt is pressed and changes win7's language, In Design will also act by changing to current character type.

      2. I will change win7's current language from inside In Desing.

       

      Does any of you know how I can do any of those two options.

      Any other good suggestion will be fine as well.

       

      Thanks

        • 1. Re: Changing English to Hebrew and vice versa
          Trevorׅ Adobe Community Professional

          Mac or Windows?

          • 3. Re: Changing English to Hebrew and vice versa
            Trevorׅ Adobe Community Professional

            Hi Nadav,

             

            Ok my question above was a great illustration of how carefully I read your opening post, it only mentions win7 3 time. Well I'm sure the students read your book will read the questions more carefully (Not so sure as it happens).

             

            Either way to allocate alt shift as the sort cut to the script you need is a bad idea, very bad besides being technically very tough if not impossible the short cut would have a global effect on indesign that when ever you want to change the language it would try to set the character styles.

             

            The most sensible way I think is to have to scripts with 2 shortcuts you could try Alt (Shift) E for English and Alt (shift) D or H for Hebrew

            Have them both use the vb Send keys command to apply the Alt Shift language swap and then for the one apply the Englis character style and the other the Hebrew one.

             

            Such a script would look like this, so just save 2 copies of the script and change the names to the correct stle names.

            var mySelection = app.selection && app.selection[0].insertionPoints[-1]; 
            !mySelection.hasOwnProperty ('baseline') && exit();
            var myCharacterStyle = app.activeDocument.characterStyles.itemByName("e"); // change to style name
            !myCharacterStyle.isValid && exit();
            var altShift = '''Set objShell = CreateObject("WScript.Shell")\
                                  objShell.SendKeys "+%"'''
            app.doScript (altShift, ScriptLanguage.VISUAL_BASIC, undefined, UndoModes.AUTO_UNDO);
            mySelection.appliedCharacterStyle = myCharacterStyle;
            

             

            It would be much more useful if we could test to see which language was the current entry language but this is very difficult.

            In theory if one uses objShell.SendKeys "a" then it is as if the "a" key has been pressed so then if the language has been set to English a "a" will be typed and if the current language is set to Hebrew then a "ש" (Shin the Hebrew letter that appears on the "a" key) will be typed. It should be easy to check which letter was typed but because of asynchronous timing problems it's tough.

             

            Bellow is another option that will work better on a Mac

             

             

            // given that you have 2 character styles one called "e" and one called "h"
            // assign a keybord shortcut maybe Alt Shift E but not just Alt Shift
            var mySelection = app.selection && app.selection[0].insertionPoints[-1]; 
            var isMac = $.os[0]==="M";
            !mySelection.hasOwnProperty ('baseline') && exit();
            var h = app.activeDocument.characterStyles.itemByName("h"); // change to Hebrew style name
            var e = app.activeDocument.characterStyles.itemByName("e"); // change to English style name
            !e.isValid && !e.isValid && exit();
            if (isMac) {
                if (mySelection.appliedCharacterStyle == e) {
                    mySelection.appliedCharacterStyle = h;
                    var applescriptHebrew = """tell application "System Events" to tell process "SystemUIServer"
            tell (1st menu bar item of menu bar 1 whose value of attribute "AXDescription" is "text input")
            return {its value, click, click menu 1's menu item "Hebrew"}
            end tell
            end tell
            """;
                    app.doScript(applescriptHebrew, ScriptLanguage.APPLESCRIPT_LANGUAGE, undefined, UndoModes.AUTO_UNDO);
                }
                else  if (mySelection.appliedCharacterStyle == h) {
                    mySelection.appliedCharacterStyle =e;
                    var applescriptEnglish = """tell application "System Events" to tell process "SystemUIServer"
            tell (1st menu bar item of menu bar 1 whose value of attribute "AXDescription" is "text input")
            return {its value, click, click menu 1's menu item "U.S."}
            end tell
            end tell
            """
                    app.doScript(applescriptEnglish, ScriptLanguage.APPLESCRIPT_LANGUAGE, undefined, UndoModes.AUTO_UNDO);
                }
            }
            else { // windows
                var altShift = '''Set objShell = CreateObject("WScript.Shell")\
                                objShell.SendKeys "+%"'''
                app.doScript (altShift, ScriptLanguage.VISUAL_BASIC, undefined, UndoModes.AUTO_UNDO);
                if (mySelection.appliedCharacterStyle != h) mySelection.appliedCharacterStyle = h else mySelection.appliedCharacterStyle = e; 
            }
            // probably easier with windows to have 2 scripts one for English and one for Hebrew
            // Change the if ... line to mySelection.appliedCharacterStyle = h for the one script and = e for the other
            
            

             

            Hope that Helps, and if it does please mark answer as correct,

             

            Trevor

            • 4. Re: Changing English to Hebrew and vice versa
              Nadav Level 1

              Hi Trevor,

               

              I did notice your exceptional reading of my opening post. I decided however, to be patient about it . Obviously, it was worth it.

              Your suggestion of sending Alt + Shift using visual basic solved the problem.

              In order to make sure I don't change the language twice I just checked the current character style and change the language only if it isn't the required character style.
              it isn't perfect, but if I keep changing the language only with the english/hebrew scripts it will probably be consistent enough.

              I marked your answer as correct.

               

              Thanks,

              Nadav