Created
January 31, 2015 10:19
-
-
Save hnakamur/a05d89f33379473aac08 to your computer and use it in GitHub Desktop.
A JavaScript.NET script for adding Japanese language to Modern.IE 32bit Windows 8 (MIT License)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Windows.Automation; | |
import System.Threading; | |
import System.Diagnostics; | |
Process.Start("C:\\Windows\\system32\\control.exe"); | |
function waitForTopLevelWindowWithName(name) { | |
var cond = new PropertyCondition(AutomationElement.NameProperty, name); | |
while (true) { | |
var win = AutomationElement.RootElement.FindFirst(TreeScope.Children, cond); | |
if (win) { | |
return win; | |
} | |
Thread.Sleep(100); | |
} | |
} | |
function waitFindFirstDescendant(elem, cond) { | |
while (true) { | |
var match = elem.FindFirst(TreeScope.Descendants, cond); | |
if (match) { | |
return match; | |
} | |
Thread.Sleep(100); | |
} | |
} | |
var cPanelWin = waitForTopLevelWindowWithName("Control Panel"); | |
var addLangLinkCond = new AndCondition( | |
new PropertyCondition(AutomationElement.AutomationIdProperty, "tasklink") , | |
new PropertyCondition(AutomationElement.NameProperty, "Add a language") | |
); | |
var addLangLink = waitFindFirstDescendant(cPanelWin, addLangLinkCond); | |
addLangLink.GetCurrentPattern(InvokePattern.Pattern).Invoke(); | |
var langWin = waitForTopLevelWindowWithName("Language"); | |
var addLangBtnCond = new PropertyCondition(AutomationElement.AutomationIdProperty, "AddALanguageButton_TB") | |
var addLangBtn = waitFindFirstDescendant(langWin, addLangBtnCond); | |
addLangBtn.GetCurrentPattern(InvokePattern.Pattern).Invoke(); | |
var addLangWin = waitForTopLevelWindowWithName("Add languages"); | |
var japaneseListItemCond = new AndCondition( | |
new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "list item") , | |
new PropertyCondition(AutomationElement.NameProperty, "Japanese") | |
); | |
var japaneseListItem = waitFindFirstDescendant(langWin, japaneseListItemCond); | |
japaneseListItem.GetCurrentPattern(InvokePattern.Pattern).Invoke(); | |
var addBtnCond = new PropertyCondition(AutomationElement.AutomationIdProperty, "AddToLanguageList") | |
var addBtn = waitFindFirstDescendant(addLangWin, addBtnCond); | |
addBtn.GetCurrentPattern(InvokePattern.Pattern).Invoke(); | |
var langWin = waitForTopLevelWindowWithName("Language"); | |
var jaTextCond = new AndCondition( | |
new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "text") , | |
new PropertyCondition(AutomationElement.NameProperty, "ja") | |
); | |
var jaText = waitFindFirstDescendant(langWin, jaTextCond); | |
var jaListItem = TreeWalker.ControlViewWalker.GetParent(jaText); | |
jaListItem.GetCurrentPattern(InvokePattern.Pattern).Invoke(); | |
var moveUpBtnCond = new PropertyCondition(AutomationElement.AutomationIdProperty, "MoveUpButton_TB") | |
var moveUpBtn = waitFindFirstDescendant(langWin, moveUpBtnCond); | |
moveUpBtn.GetCurrentPattern(InvokePattern.Pattern).Invoke(); | |
var closeBtnCond = new PropertyCondition(AutomationElement.AutomationIdProperty, "Close") | |
var closeBtn = waitFindFirstDescendant(langWin, closeBtnCond); | |
closeBtn.GetCurrentPattern(InvokePattern.Pattern).Invoke(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jsc /lib:C:\Windows\Microsoft.NET\Framework\v4.0.30319\WPF /reference:UIAutomationClient.dll;UIAutomationTypes.dll addLang.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment