Automate Logos (Notes) with Powershell

Page 1 of 1 (12 items)
This post has 11 Replies | 4 Followers

Posts 313
PJ | Forum Activity | Posted: Wed, Dec 16 2015 3:20 AM

Note Automation

Creating Notes from a Template could be useful in some situations. I created this powershell solution to do just that. I tried to keep the implementation as simple as possible.

  1. Download and extract all files in AutoNotes.zip file to one directory
  2. Drag the "Sample Template.vbs" into Logos to create a Button on the ToolBar
  3. Create an empty Note Document
  4. Make sure the Active Panel is the Note you created
  5. Click the Button you created
  6. It will create 7 Notes from the Template

This is what the sample script will generate:

Your own Template

To create your own template:

  1. Make a copy of "Template1.ps1" and save it with any name
  2. Edit the content of the new file
  3. Make a copy of "Sample Template.vbs" and save with a new name
  4. Change the "tmp" variable to point to the copy of "Template1.ps1" file you modified
  5. Drag and drop the vbscript file to create a button in Logos
  6. Create an empty Note Document
  7. Make sure it's the Active Panel
  8. Click the Button you created

System

  • Win 10
  • Powershell  5 (10586)
  • Logos Bible Software 6.8 (6.8.0.0049)

Notes

I used Keyboard shortcuts to Toggle Bold, so please do not do anything until the template is complete. I'm investigating to use TogglePattern.Pattern.Invoke on all buttons in the Notes Panel.

The syntax for Template creation is in the "Template1.ps1" file.

Enjoy - and please inform me of any bugs

Posts 26021
Forum MVP
MJ. Smith | Forum Activity | Replied: Wed, Dec 16 2015 2:23 PM

Excellent!

Orthodox Bishop Hilarion Alfeyev: "To be a theologian means to have experience of a personal encounter with God through prayer and worship."

Posts 313
PJ | Forum Activity | Replied: Fri, Dec 18 2015 8:32 PM

Does anyone know how to add EventHandlers for LogosComApi in Powershell? I know I'm missing something: $this.ComApplication holds the Launcher.Application object.

Register-ObjectEvent -InputObject $this.ComApplication -EventName PanelActivated -Action {
        Out-Host "<PanelActivated>"
       
}

I want to improve the Note script to do much more. Behind the scenes of the sample script is much more power (I'll add the complete version later). You can automate almost anything like with AutoIt, just a lot easier, right in PowerShell.

Sample:

$Logos = [Logos]::new()

With ($Logos.Home){

 .Show($)

 .Customize.Show().Select("Start Prayer List")

}


With ($Logos.CommandBox){

 .SetText("Close All")
 .Execute($)

}

$Logos.Search.Invoke()

$Logos.Panels.Select(0)

With ($Logos.Panels.Automation){

 .SearchBasic($)

 .SearchText("Paul")

 .Search($)

}

The idea is to make use of PowerShell as an easy MacroEditor. Here is a preview of the MacroEngine.

NB: The Withblock is a custom function, always pass a ($) and not empty brackets (), otherwise the script will crash.

8182.MacroEngine.zip

Posts 2235
Beloved | Forum Activity | Replied: Fri, Dec 18 2015 9:22 PM

Chrome blocks as malicious file. Help

Meanwhile, Jesus kept on growing wiser and more mature, and in favor with God and his fellow man.

International Standard Version. (2011). (Lk 2:52). Yorba Linda, CA: ISV Foundation.

Posts 313
PJ | Forum Activity | Replied: Sat, Dec 19 2015 8:42 AM

Does it block the download or the script from execution?

Posts 2235
Beloved | Forum Activity | Replied: Sat, Dec 19 2015 3:51 PM

the download

Meanwhile, Jesus kept on growing wiser and more mature, and in favor with God and his fellow man.

International Standard Version. (2011). (Lk 2:52). Yorba Linda, CA: ISV Foundation.

Posts 313
PJ | Forum Activity | Replied: Sat, Dec 19 2015 8:31 PM

AutoNotes.Zip

AutoNotes.ps1

#Logos Bible Software Note Automation
#Created : Des 2015
#Developer: PJ Kotze

$AssemblyPath = "$env:programfiles\Reference Assemblies\Microsoft\Framework\v3.0"
[void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationClient")
[void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationTypes")
add-type -AssemblyName System.Windows.Forms
[Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
$DebugViewWindow_TypeDef = @'
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string ClassName, string Title);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out System.Drawing.Point pt);
 
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
 
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
 
public static void LeftClick(){
    mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

}
 
public static void RightClick(){
    mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
}
'@

Add-Type -MemberDefinition $DebugViewWindow_TypeDef -Namespace AutoClicker -Name Temp -ReferencedAssemblies System.Drawing

#=========================================
# FUNCTIONS
#=========================================

Function GetLogosWindow
{
   
    #Get Logos Window
        $AppCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::NameProperty, "Logos Bible Software")
        $ClassCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::ClassNameProperty, "Window")
        $AndCon = New-Object Windows.Automation.AndCondition($AppCon, $ClassCon)

        return [Windows.Automation.AutomationElement]$Desktop.FindFirst([Windows.Automation.TreeScope]::Descendants, $AndCon) 
     
   
}
Function GetNotePanel($Title){
    $TabCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::NameProperty, $Title)
    $ClassCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::ClassNameProperty, "TabItem")
    $AndCon = New-Object Windows.Automation.AndCondition($TabCon, $ClassCon)
    return [Windows.Automation.AutomationElement]$Logos.FindFirst([Windows.Automation.TreeScope]::Descendants, $AndCon)
}
Function GetDesktopWindow
{
    return [Windows.Automation.AutomationElement]::RootElement
}
Function GetAddNote
{
    $con = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::NameProperty, "Add note")
    $btn = [Windows.Automation.AutomationElement]$Notes.FindFirst([Windows.Automation.TreeScope]::Descendants, $con)
    return $btn.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern)
}
Function LoadItems()
{
    $NP = GetNotePanel $ActiveTitle 
    $con = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::ClassNameProperty, "NoteViewControl")
    return $NP.FindAll([Windows.Automation.TreeScope]::Descendants, $con)
}
Function SelectAll
{
    [System.Windows.Forms.SendKeys]::SendWait("^a")
}
Function SelectItem ($index)
{ 
    $Items = LoadItems     
    $cpt = $Items.Item($index).GetClickablePoint()
    [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(($cpt.X), ($cpt.Y))

    [AutoClicker.Temp]::LeftClick()
    
}
Function SelectTitle($index)
{
    $Items = LoadItems 
    $con = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::AutomationIdProperty, "TitleRichTextEditor")
    $theTitle = $Items.Item($index).FindFirst([Windows.Automation.TreeScope]::Descendants, $con)
    $theTitle.SetFocus()
}
Function SetTitle($index, $title, $bold, $indentation)
{    
    SelectTitle $index 
    SelectAll
    
    [System.Windows.Forms.SendKeys]::SendWait($title)
    If ($bold -eq $TRUE) {
        SelectAll
        ToggleBold
    }
    If ($indentation -ge 1)
    {
        Indent $index $indentation
    }
}
Function SelectContent($index)
{
    $Items = LoadItems 
    SelectItem $index
    $con = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::AutomationIdProperty, "ContentRichTextEditor")
    $theContent = $Items.Item($index).FindFirst([Windows.Automation.TreeScope]::Descendants, $con)
    $theContent.SetFocus()
}
Function SetContent($index, $content)
{    
    #Sometimes Content isn't visible
    #so we need to select the item to force visibility of content
    
    SelectContent $index
    SelectAll
    [System.Windows.Forms.SendKeys]::SendWait($content)
}
Function GetIndentButton
{
    $con = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::HelpTextProperty, "Increase note indentation")
    $btn =$Notes.FindFirst([Windows.Automation.TreeScope]::Descendants, $con)
    return $btn.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern)
}
Function GetToggleButton($AutomationId)
{
    $con = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::AutomationIdProperty, $AutomationId)
    $btn =$Notes.FindFirst([Windows.Automation.TreeScope]::Descendants, $con)
    return $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
}
Function Indent($index, $counter)
{
    $Indent = GetIndentButton 
    SelectItem $index   
     
    For ($i=1;$i -le $counter;$i++)
    {
        $Indent.Invoke()
    }
            
}
Function AddNotes($count)
{
    For ($i=1;$i -le $count; $i++)
    {
        $AddNote.Invoke()
    } 
     
    $Items = LoadItems
}
Function ToggleBold
{
    #[Windows.Automation.TogglePattern]$button = GetToggleButton "ToggleBold"
    #$button.Toggle()
    [System.Windows.Forms.SendKeys]::SendWait("^b^{END}")
}
<# Function CreateNotes() { $CurrentTitle = $L.Application.GetActivePanel().Title $con = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::AutomationIdProperty, "CommandTextBox") $box =$Logos.FindFirst([Windows.Automation.TreeScope]::Descendants, $con) $pattern = $box.GetCurrentPattern([Windows.Automation.ValuePattern]::Pattern) $pattern.SetValue("Create Notes") $con = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::AutomationIdProperty, "ActionButton") $btn = $Logos.FindFirst([Windows.Automation.TreeScope]::Descendants, $con) $inv = $btn.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern) $inv.Invoke() Do { $ActiveTitle = $LogosComApi.GetActivePanel().Title } While ($ActiveTitle -eq $CurrentTitle) $Notes = GetNotePanel $ActiveTitle $AddNote = GetAddNote $Items = LoadItems } #>

#=========================================
# START
#=========================================
Write "====================================="
Write "Logos Bible Software Notes Automation" 
Write "Copyright 2015"
Write "PJ Kotze"
Write "====================================="
Write ""
#=========================================
# VARIABLES
#=========================================

#[System.Drawing.Point]$pt
[Windows.Automation.AutomationElement]$Desktop  
[Windows.Automation.AutomationElement]$Logos 
[Windows.Automation.AutomationElement]$Notes

[String]$ActiveTitle
[Windows.Automation.InvokePattern]$AddNote

$Items


 
$LogosComApi
$launcher = New-Object -ComObject LogosBibleSoftware.Launcher     
$launcher.LaunchApplication()
        Do
        {
            $LogosComApi = $launcher.Application
        } While ($LogosComApi –eq $null)

 
$Desktop = GetDesktopWindow
$Logos = GetLogosWindow


#Run script only if the ActivePanel is of Kind Notes
if ($LogosComApi.GetActivePanel().Kind -eq "Notes"){
    $ActiveTitle = $LogosComApi.GetActivePanel().Title
    $Notes = GetNotePanel $ActiveTitle 
    $AddNote = GetAddNote      
    $Items = LoadItems
}

Template1.ps1

#Load the Automation Module
Import-Module -Name $PSScriptRoot\AutoNotes.ps1 -Force
cls

#Check if the ActiveTitle is null
#Only run Template if it is not null
If ($ActiveTitle -ne $null)
{

    #AddNotes(HowManyNotes)
    AddNotes(7) 

    #SetTitle index title bold [indentationlevel]
    #Remember it is 0 based: use (0-6) not (1-7) below as index
    SetTitle 0 "Heading 1" True
    SetTitle 1 "SubHeading 1" False 1
    SetTitle 2 "SubHeading 2" False 1
    SetTitle 3 "SubHeading 3" False 1
    SetTitle 4 "Heading 2" True
    SetTitle 5 "SubHeading 1" False 1
    SetTitle 6 "SubHeading 2" False 1

}

Sample Template.vbs

'I run the powershell script from vbs
'to prevent powershell from popping up a console

tmp = "Template1.ps1"
scriptdir = WScript.ScriptFullName 
ipos = InstrRev(scriptdir,"\")

command = "powershell.exe -nologo -command " & left(scriptdir,ipos) & tmp
 
set shell = CreateObject("WScript.Shell")
shell.Run command,0

Posts 313
PJ | Forum Activity | Replied: Sat, Dec 19 2015 8:58 PM

This is the original file as in the zip. I did learn a lot about powershell by writing this code so there is an improved version available later if anyone should be interested to use or maybe improve on the idea.

MacroEngine.ps1

#region "References"
#MACROENGINE
#PJ KOTZE
#2015
$AssemblyPath = "$env:programfiles\Reference Assemblies\Microsoft\Framework\v3.0"
[void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationClient")
[void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationTypes")
add-type -AssemblyName System.Windows.Forms
[Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
$DebugViewWindow_TypeDef = @'
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string ClassName, string Title);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out System.Drawing.Point pt);
 
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
 
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
private const int MOUSEEVENTF_RIGHTUP = 0x10;
 
public static void LeftClick(){
    mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

}
 
public static void RightClick(){
    mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
}
'@

Add-Type -MemberDefinition $DebugViewWindow_TypeDef -Namespace AutoClicker -Name Temp -ReferencedAssemblies System.Drawing
#endregion

#region "Application"
[Windows.Automation.AutomationElement]$Global:AutomationElement
[int32]$WaitDefault
#region "Functions
    Function Click-Element($elem){
            $cpt = $elem.GetClickablePoint()           
        
            [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(($cpt.X), ($cpt.Y))
            [AutoClicker.Temp]::LeftClick()
    }
    Function Get-Element($className, $Property, $propertyValue,$parent){
            try
            {

            $NameCon = New-Object Windows.Automation.PropertyCondition($Property, $propertyValue)
            $ClassCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::ClassNameProperty, $className)
            $AndCon = New-Object Windows.Automation.AndCondition($NameCon, $ClassCon)
            $EnabledCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::IsEnabledProperty, $True)
            $AndCon = New-Object Windows.Automation.AndCondition($EnabledCon, $AndCon)

            return [Windows.Automation.AutomationElement]$parent.FindFirst([Windows.Automation.TreeScope]::Descendants, $AndCon)
            } catch {
                return $null
            }
        }
    Function Set-Text($txtBox,$text){
            $pattern = $txtBox.GetCurrentPattern([Windows.Automation.ValuePattern]::Pattern)
            $pattern.SetValue($text)
        }
    Function Invoke-Button($btn){        
            [Windows.Automation.InvokePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern)
            $pattern.Invoke()
        }
    Function with($object,$scriptBlock){
        ($object) | ForEach-Object {
        $code = ($scriptBlock).ToString()
        $code = $code.Replace(" ."," `$_.")
        $code = $code.Replace(" ."," `$_.")
        $code = $code.Replace("(`$)","()")
        #$code = $code.Replace("<>","()")
        Invoke-Expression ($code)
        }
     
    }
    Function Get-TabItems(){
            $ClassCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::ClassNameProperty, "TabItem")  
            $IsKeyboardFocusableCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::IsKeyboardFocusableProperty, $True)  
            $AndCon = New-Object Windows.Automation.AndCondition ($ClassCon, $IsKeyboardFocusableCon)
            [Windows.Automation.AutomationElementCollection]$Collection = [Windows.Automation.AutomationElementCollection]$Global:AutomationElement.FindAll([Windows.Automation.TreeScope]::Descendants, $AndCon)
            return [Windows.Automation.AutomationElementCollection]$Collection
        }
#endregion

Class Logos{
    [String]$MainWindowTitle = (Get-Process -Name Logos).MainWindowTitle
    $ComApplication = $null

    [Home]$Home = [Home]::new()
    [Library]$Library = [Library]::new()
    [Search]$Search = [Search]::new()

    [CommandBox]$CommandBox = [CommandBox]::new()
    [Documents]$Documents = [Documents]::new()
    [Guides]$Guides = [Guides]::new()
    [Tools]$Tools = [Tools]::new()
    [Shortcuts]$Shortcuts = [Shortcuts]::new()
    [Layouts]$Layouts = [Layouts]::new()
    [Help]$Help = [Help]::new()

    [Panels]$Panels = [Panels]::new()

    Logos(){
        #$launcher = New-Object -ComObject LogosBibleSoftware.Launcher
        #$launcher.LaunchApplication()
        #Do {} until ($this.ComApplication = $launcher.Application)

        $Desktop = [System.Windows.Automation.AutomationElement]::RootElement
        $NameCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::NameProperty, $this.MainWindowTitle)
        $ClassCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::ClassNameProperty, "Window")
        $AndCon = New-Object Windows.Automation.AndCondition($NameCon, $ClassCon)   
        $Global:AutomationElement = $Desktop.FindFirst([Windows.Automation.TreeScope]::Descendants, $AndCon) 
        #When Logos starts not all elements is visible yet
        #Wait until the CommandBox is visible, then all will be ok'
        $btn = $null
        do
        {
            $btn = Get-Element "TextBox" ([Windows.Automation.AutomationElement]::AutomationIdProperty) "CommandTextBox" $Global:AutomationElement
        } while ($btn -eq $null)

        #$Global:AutomationElement = $Desktop.FindFirst([Windows.Automation.TreeScope]::Descendants, $AndCon)

        <#
        Register-ObjectEvent -InputObject $this.ComApplication -EventName PanelActivated -Action {
        Out-Host "<PanelActivated>"
        }

        #>
        #$this.ComApplication.Activate()
    }
    
    Idle($sec){
        Start-Sleep $sec
        }
    Write($text){
        [System.Windows.Forms.SendKeys]::SendWait($text)
    }
    Minimize(){        
        Invoke-Button(Get-Element "Button"   ([Windows.Automation.AutomationElement]::NameProperty) "Minimize" $Global:AutomationElement)
    }
    Maximize(){
        Invoke-Button(Get-Element "Button" ([Windows.Automation.AutomationElement]::NameProperty)   "Maximize" $Global:AutomationElement)
    }
    Restore(){
        Invoke-Button(Get-Element "Button" ([Windows.Automation.AutomationElement]::NameProperty)    "Restore" $Global:AutomationElement)
    }
    Close(){
        Invoke-Button(Get-Element "Button" ([Windows.Automation.AutomationElement]::NameProperty)    "Close" $Global:AutomationElement)
    }
    Synchronize(){
        Invoke-Button(Get-Element "Button" ([Windows.Automation.AutomationElement]::NameProperty)    "Synchronization" $Global:AutomationElement)
    }
        
}
Class CommandBox{
     
    SetText($cmd){
       
        $btn = Get-Element "TextBox"  ([Windows.Automation.AutomationElement]::AutomationIdProperty)  "CommandTextBox" $Global:AutomationElement
        Set-Text $btn $cmd 
               
        }
        

    Execute($pause){          
        $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::AutomationIdProperty)  "ActionButton" $Global:AutomationElement
        Invoke-Button $btn
        
        Start-Sleep $pause
       }
}

#region "ToolBar
    Class Documents{
        [Documents]Show(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Documents" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::Off){$pattern.Toggle()}
            return $this
        }
        Hide(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Documents" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::On){$pattern.Toggle()}
        }
        Find($value){
            $btn = Get-Element "TextBox"  ([Windows.Automation.AutomationElement]::AutomationIdProperty)  "FilterTextBox" $Global:AutomationElement
            Set-Text $btn $value
        }
        Open($itemName){
         
            $btn = Get-Element "ListBoxItem"  ([Windows.Automation.AutomationElement]::NameProperty)  $itemName $Global:AutomationElement
            Click-Element $btn
        }
    
    }
    Class Guides{
        [Guides]Show(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Guides" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::Off){$pattern.Toggle()}
            return $this
        }
        Hide(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Guides" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::On){$pattern.Toggle()}
        }
        Find($value){
            $btn = Get-Element "TextBox"  ([Windows.Automation.AutomationElement]::AutomationIdProperty)  "FilterTextBox" $Global:AutomationElement
            Set-Text $btn $value
        }
        Open($itemName){
         
            $btn = Get-Element "ListBoxItem"  ([Windows.Automation.AutomationElement]::NameProperty)  $itemName $Global:AutomationElement
            Click-Element $btn
        }
    }
    Class Tools{
        Show(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Tools" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::Off){$pattern.Toggle()}
        }
        Hide(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Tools" 
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::On){$pattern.Toggle()}
        }
        Open($itemName){
            $btn = Get-Element "ListBoxItem"  ([Windows.Automation.AutomationElement]::NameProperty)  $itemName $Global:AutomationElement
            Click-Element $btn
        }
    }
    Class Layouts{
        Show(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Layouts" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::Off){$pattern.Toggle()}
        }
        Hide(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Layouts"  $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::On){$pattern.Toggle()}
        }
        Open($itemName){
            $btn = Get-Element "ListBoxItem"  ([Windows.Automation.AutomationElement]::NameProperty)  $itemName $Global:AutomationElement
            Click-Element $btn
        }
    
    }
    Class Help{
        Show(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Help" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::Off){$pattern.Toggle()}
        }
        Hide(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Help" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::On){$pattern.Toggle()}
        }
        Open($itemName){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  $itemName $Global:AutomationElement
            Click-Element $btn
        }
    }
#endregion

#region "HomePage"
    Class Home{
        [Customize]$Customize=[Customize]::new()
        Show(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Home" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::Off){$pattern.Toggle()}
        }
        Hide(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Home"  $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::On){$pattern.Toggle()}
        }
        SetNavigatorText($text){
            $txtBox = Get-Element "TextBox" ([Windows.Automation.AutomationElement]::AutomationIdProperty) "NavigatorTextBox" $Global:AutomationElement
            Set-Text $txtBox $text 
        }
        Go(){
            $btn = Get-Element "Button" ([Windows.Automation.AutomationElement]::AutomationIdProperty) "BehaviorCommand"  $Global:AutomationElement
            Invoke-Button $btn
        }
 
    }
    Class Customize{
        [Customize]Show(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Customize" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::Off){$pattern.Toggle()}
            return $this
        }
        Hide(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Customize"  $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::On){$pattern.Toggle()}
        }
        Select($value){
            $btn = Get-Element "CheckBox"  ([Windows.Automation.AutomationElement]::NameProperty)  $value $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::Off){$pattern.Toggle()}
        }
        UnSelect($value){
            $btn = Get-Element "CheckBox"  ([Windows.Automation.AutomationElement]::NameProperty)  $value $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::On){$pattern.Toggle()}
        }

    }
#endregion
    Class Shortcuts{
        Open($itemName){         
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::AutomationIdProperty)  $itemName $Global:AutomationElement
            Invoke-Button $btn
        }
    }
    Class Library{
        [Library]Show(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Library" $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::Off){$pattern.Toggle()}
            return $this
        }
        Hide(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Library"  $Global:AutomationElement
            [Windows.Automation.TogglePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.TogglePattern]::Pattern)
            If ($pattern.Current.ToggleState -eq [Windows.Automation.ToggleSTate]::On){$pattern.Toggle()}
        }
    
    }

    Class Search{
        Invoke(){
            $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::NameProperty)  "Search" $Global:AutomationElement
            [Windows.Automation.InvokePattern]$invokePattern = $btn.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern)
            $invokePattern.Invoke()
        }
    
    }
    Class Panels{
 
        [Windows.Automation.AutomationElement]$SelectedItem
        [PanelsAutomation]$Automation = [PanelsAutomation]::new()

        Panels(){$this.SelectedItem=$null}
        [Int32]Count(){         
            $TabItems = Get-TabItems
            return $TabItems.Count
        }
        [Windows.Automation.AutomationElement]Item($index){         
            $TabItems = Get-TabItems
            return [Windows.Automation.AutomationElement]$TabItems.Item($index)
        }
        Select($index){
            $this.Automation.SetIndex($index)
            $TabItems = Get-TabItems
            IF ($TabItems.Count -eq 1)
            {
                $cpt = $TabItems.GetClickablePoint()
                $this.SelectedItem = $TabItems 
            } else {
                $cpt = $TabItems.Item($index).GetClickablePoint()
                $this.SelectedItem = $TabItems.Item($index)
            }
        
            [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(($cpt.X), ($cpt.Y))
            [AutoClicker.Temp]::LeftClick()
        
        
        }
     
    }
    Class PanelsAutomation{
        [int32]$Index
        [Windows.Automation.AutomationElement]$Panel
        SetIndex($index){
            $this.Index=$index
        
            $TabItems = Get-TabItems
            IF ($TabItems.Count -eq 1)
            {
                $this.Panel = [Windows.Automation.AutomationElement]$TabItems 
            } else {
                $this.Panel = [Windows.Automation.AutomationElement]$TabItems.Item($index)
            }
 
            }
            Close(){
                $NameCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::AutomationIdProperty, "CloseButton")
                $ClassCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::ClassNameProperty, "Button")
                $AndCon = New-Object Windows.Automation.AndCondition($NameCon, $ClassCon)
                $EnabledCon = New-Object Windows.Automation.PropertyCondition([Windows.Automation.AutomationElement]::IsEnabledProperty, $True)
                $AndCon = New-Object Windows.Automation.AndCondition($EnabledCon, $AndCon)

                $btn = [Windows.Automation.AutomationElement]$this.Panel.FindFirst([Windows.Automation.TreeScope]::Descendants, $AndCon)
            
                [Windows.Automation.InvokePattern]$pattern = $btn.GetCurrentPattern([Windows.Automation.InvokePattern]::Pattern)
                $pattern.Invoke()
            }
            SetSearchText($value){
                #AutoCompleterTextBox
                $btn = Get-Element "TextBox"  ([Windows.Automation.AutomationElement]::AutomationIdProperty)  "AutoCompleterTextBox" $this.Panel 
                Set-Text $btn $value 
            }
            SearchBasic(){
                $btn = Get-Element "ListBoxItem"  ([Windows.Automation.AutomationElement]::NameProperty)  "Basic" $this.Panel 
                Click-Element $btn
            
            }
            SearchBible(){
                $btn = Get-Element "ListBoxItem"  ([Windows.Automation.AutomationElement]::NameProperty)  "Bible" $this.Panel 
                Click-Element $btn            
            }
            SearchMedia(){
                $btn = Get-Element "ListBoxItem"  ([Windows.Automation.AutomationElement]::NameProperty)  "Media" $this.Panel 
                Click-Element $btn            
            }
            SearchClause(){
                $btn = Get-Element "ListBoxItem"  ([Windows.Automation.AutomationElement]::NameProperty)  "Clause" $this.Panel 
                Click-Element $btn            
            }
            SearchMorph(){
                $btn = Get-Element "ListBoxItem"  ([Windows.Automation.AutomationElement]::NameProperty)  "Morph" $this.Panel 
                Click-Element $btn            
            }
            SearchSyntax(){
                $btn = Get-Element "ListBoxItem"  ([Windows.Automation.AutomationElement]::NameProperty)  "Syntax" $this.Panel 
                Click-Element $btn            
            }
            Search(){
                $btn = Get-Element "Button"  ([Windows.Automation.AutomationElement]::AutomationIdProperty)  "ActionButton" $this.Panel 
                Invoke-Button($btn)
            }
    }
 


#endregion

Cls

Posts 313
PJ | Forum Activity | Replied: Sat, Dec 19 2015 9:12 PM

Line 130-132 in the above code should be commented. It will generate an error because I did no error handling.

Or set:  $ErrorActionPreference = "silentlycontinue"

Posts 2235
Beloved | Forum Activity | Replied: Mon, Dec 21 2015 12:16 PM

Pieter Kotze:

AutoNotes.ps1

#Logos Bible Software Note Automation
#Created : Des 2015
#Developer: PJ Kotze

Thanks Pieter for your reply.

But, what do I do with this code? Do I copy and paste into Notepad?

Meanwhile, Jesus kept on growing wiser and more mature, and in favor with God and his fellow man.

International Standard Version. (2011). (Lk 2:52). Yorba Linda, CA: ISV Foundation.

Posts 313
PJ | Forum Activity | Replied: Mon, Dec 21 2015 9:27 PM

Yes you can. Copy each and save it with the filename provided above the block of code. Just make sure when you "save as" to select "All Files (*.*)" as "Save as type:". Save all files into one directory. Then follow the instructions in the first post.

If you never used powershell you will propably run into a nasty error in red stating that the code can't run. You will need to set the execution policy. Start Powershell as Administrator then type the policy you want into the console and press enter.

Policy:

  • Restricted: Default execution policy, does not run scripts, interactive commands only.
  • All Signed: Runs scripts; all scripts and configuration files must be signed by a publisher that you trust; opens you to the risk of running signed (but malicious) scripts, after confirming that you trust the publisher.
  • Remote Signed: Local scripts run without signature. Any downloaded scripts need a digital signature, even a UNC path.
  • Unrestricted:Runs scripts; all scripts and configuration files downloaded from communication applications such as Microsoft Outlook, Internet Explorer, Outlook Express and Windows Messenger run after confirming that you understand the file originated from the Internet; no digital signature is required; opens you to the risk of running unsigned, malicious scripts downloaded from these applications

Set-ExecutionPolicy [PolicyName]

example: Set-ExecutionPolicy Unrestricted

Posts 313
PJ | Forum Activity | Replied: Thu, Dec 22 2016 10:37 PM

See Creating Note Templates for other existing solutions and a AutoHotKey Solution. (Do not use this script before you moved/backup Note Files in Documents\Libronix DLS\Annotations folder)

54
Page 1 of 1 (12 items) | RSS