[NFBCS] script to access nearest console window for package manager

Ty Littlefield tyler at tysdomain.com
Mon Sep 9 20:52:39 UTC 2024


Hi,

Someone asked about this quite a while back and I promised to provide it 
and forgot.

Bind this to whatever key you want. If you're unlucky enough to have to 
use the nuget package manager, here's how you can easily get to that 
console to review output. YMMV with this thing, I'm by no means a script 
expert and I'm sure plenty of people could write it more cleanly and 
better. This was a quick hour fix when I needed it.

import "uia.jsb"
import "touch.jsb"
include "uia.jsh"
include "hjconst.jsh"
include "hjglobal.jsh"

Script VirtualizeNearestConsoleWindow ()
var handle appWindow = GetAppMainWindow (GetCurrentWindow())
var object UIAObject = FSUIAGetElementFromHandle(appWindow)
if (!UIAObject) then
SayString("Could not create UIA object.")
return
EndIf
var object controlCondition = 
FSUIACreateIntPropertyCondition(UIA_ControlTypePropertyId, 
UIA_PaneControlTypeId)
var object nameCondition = 
FSUIACreateStringPropertyCondition(UIA_NamePropertyId, "Package Manager 
Console")
if (!controlCondition || !nameCondition) then
SayString("Could not create conditions.");
return
EndIF
var object finalCondition = FSUIACreateAndCondition(controlCondition, 
nameCondition)
if (!finalCondition)
SayString("Could not create conditions.");
return
EndIf
var object pane = uiaObject.findFirst(TreeScope_Subtree, finalCondition)
if (!pane)
SayString("Could not find pane.")
return
EndIf
var object textboxCondition = 
FSUIACreateStringPropertyCondition(UIA_NamePropertyId, "Text Editor")
if (!textboxCondition)
SayString("Could not create textbox condition.")
return
EndIf
var object textbox = pane.findFirst(TreeScope_Subtree, textboxCondition)
SayString(textbox.name)
var object textPattern = textbox.GetTextPattern()
if (!textPattern) then
SayString("Could not get text pattern.")
return
EndIf
var object range = textPattern.documentRange
     if !range then
     SayString("could not get range.")
     return
     EndIf
     range.ExpandToEnclosingUnit(TextUnit_Page)
var string value = range.getText(TextRange_NoMaxLength)
     UserBufferClear()
UserBufferAddText(value)
UserBufferActivate()
EndScript

-- 

*Ty Littlefield*
Software Developer | Blogger | Audio Engineer

Cell: (720) 314-8194
Blog: From Bytes to Bites <https://tysdomain.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nfbnet.org/pipermail/nfbcs_nfbnet.org/attachments/20240909/7c0cca17/attachment.htm>


More information about the NFBCS mailing list