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