HowTo open a Layout with a Link (Tip)

Pieter J.
Pieter J. Member Posts: 533
edited November 2024 in English Forum

It's not possible to use the logos4 protocol to open a layout. I made a small AutoHotkey script to acomplish just this.

How it works

By renaming the Logos.exe file in %UserProfile%\AppData\Local\Logos\Logos.exe to Logos8.exe I can now compile a small ahk executable and name it logos.exe and put it in the same directory.

This small file handles the logos4 protocol and if it finds my new "layout" command it opens the Layout else it forwards to logos8.exe where it was originally intended to go.

In Logos I can now use my custom link, logos4:layout|Bible and Commentary

This script can only handle spaces and the pipe char as I don't need any extra functionality. I just thought to share this trick as I saw a lot of users strugling with this restriction.

The possibilities of what you can do next with this sample is actually awesome. But, I leave this creative expidition to you ...

Source Code (AutoHotKey)

#SingleInstance Force
#Persistent
#NoEnv

HayStack = %1%
Needle := "layout"

If InStr(HayStack, Needle)
{
arr := StrSplit(HayStack,"%7C")
inputstr := arr[2]
StringReplace, output,inputstr,`%20,%A_Space%,All
comobj := ComObjActive("LogosBibleSoftware.Application")
comobj.LoadLayout(output)
}
Else
run, %A_ScriptDir%\Logos8.exe ,"%1%"

ExitApp
Tagged:

Comments

  • Fred Chapman
    Fred Chapman Member Posts: 5,899 ✭✭✭

    I'm not a techie, but if I understand your post, this hotkey script opens Logos to a specific saved layout. Is that correct?

    If my understanding is correct, how does that differ from setting Logos to open a specific layout in Program Settings?

  • Pieter J.
    Pieter J. Member Posts: 533

    this hotkey script opens Logos to a specific saved layout. Is that correct?

    Yes, this is correct.

    how does that differ from setting Logos to open a specific layout in Program Settings?

    With some extra coding you can link a Layout of your choice from anywhere in Logos where you can insert a link. You can capture the headword or reference of any open panel and pass it on to the new Layout's Resource, Guide or Tool of your choice.

    Let's say you are working in a Workflow. When you click on a link it can open a new Layout, using your code, and pass the Reference you are working to another Workflow.

    This isn't the savest way to do this, there are another option but requires a running script and a lot more code. I think that FaithLife should look into this discovery as it can be a security threat. Links from the Software should not be able to pass anything other than acceptable information via the protocol.

  • Doc B
    Doc B Member Posts: 3,594 ✭✭✭

    PJ said:

    it can be a security threat

    If I understand your explanation, it can only be a threat for those who rename their app. No?

    Eating a steady diet of government cheese, and living in a van down by the river.

  • Pieter J.
    Pieter J. Member Posts: 533

    Doc B said:

    it can only be a threat for those who rename their app. No?

    Maybe I read to much on how trojans sneak into systems. I asked Faithlife to look into this. I don't think any software should allow this kind of scripting to fool it and doesn't feel comfortable that this is even possible. The weakness is that there is no verification between the application and the registry to verify that something changed. I don't feel comfortable to give more technical information on this. I would love to be wrong, but from how I look at it, it should be a concern.

  • Bradley Grainger (Logos)
    Bradley Grainger (Logos) Administrator, Logos Employee Posts: 11,997

    PJ said:

    I think that FaithLife should look into this discovery as it can be a security threat.

    PJ said:

    Maybe I read to much on how trojans sneak into systems.

    If this were a problem in the default installation of Logos 8, we would investigate it.

    If there's already malware on the system changing the registry, then the computer is compromised and there's nothing we could do to mitigate that. (Advanced malware could circumvent our "verification between the application and the registry" to fool Logos into thinking the registry wasn't changed.)

    A Microsoft developer has a post about a similar situation: https://devblogs.microsoft.com/oldnewthing/20190109-00/?p=100665 

  • Pieter J.
    Pieter J. Member Posts: 533

    A Microsoft developer has a post about a similar situation: https://devblogs.microsoft.com/oldnewthing/20190109-00/?p=100665 

    I intercepted the humor behind this Bradley. I appreciate the clear well defined answer. I'll try to give more "selfsafe" solutions to problems.

  • Pieter J.
    Pieter J. Member Posts: 533

    I officially abandon the above approach. The following is then the better, saver solution.

    • Give the script a filename corresponding to the layout you want to open.
    • Add the Script as a Button on the Shortcuts bar
    • The Script Takes the Active Panel's reference and transfer it to the new Layout's Active Panel
    • This will work for Bibles (Tested only against Bibles)

    I didn't check this code under all possible configurations. It should work if Source and Destination Panels take the same Reference. There are obviously room for improvement, but this should give those struggling with initializing layouts to a reference a start. This code can easily be ported to another scripting language. If you do so, please add it for others that want to make use of it.

    CODE

    #SingleInstance Force
    #NoEnv

    ;Copy and Paste the Code to NotePad or Prefered Editor for AHK
    ;Save the File with the Name of the Layout You Want To Open
    ;Example: My New Layout.ahk
    ;Add the Script as a Button to the Shortcuts bar

    ;=============================================================
    ; Only need to fix bugs if any popup
    ; The code will open the layout using it's FileName
    ;=============================================================
    ;Check if it's a compiled script
    If (Instr (A_ScriptName,.exe)==True)
    {
    ;Capture the Filename to be used as Layout removing the extention .exe
    StringReplace, layout, A_ScriptName, .exe, ,All
    } else {
    ;Capture the Filename to be used as Layout removing the extention .ahk
    StringReplace, layout, A_ScriptName, .ahk, ,All
    }

    ;Attach the Script to the running Software Instance
    Logos := ComObjActive("LogosBibleSoftware.Application")

    ;Get the Active Panel
    ActivePanel := Logos.GetActivePanel
    ;Get the first Headword Entry
    Ref := ActivePanel.GetCurrentReferencesAndHeadwords.Item[0]
    ;Create a Navigation Request
    NavigationRequest := Logos.CreateNavigationRequest
    ;Set the Navigation Request to the reference of the ActivePanel
    NavigationRequest.Reference := Ref.Reference

    ;Load the layout
    Logos.LoadLayout(layout)

    ;Get the ActivePanel in the Destination Layout
    DestinationPanel := Logos.GetActivePanel
    ;Request the Panel to Navigate to the Reference
    DestinationPanel.Navigate(NavigationRequest)

    ;The Script will now exit