Automate 'replace with passage' in Word Add-in using keyboard shortcut?

John Duffy
John Duffy Member Posts: 591 ✭✭✭
edited November 2024 in English Forum

Hi, has anyone been able to automate in Word the Add-in to replace a reference with the passage?  (Right-click > Additional Actions > Replace with passage)  I've tried to record a macro to do it, but it won't record right-clicks.  VBA Sendkeys doesn't work either, and isn't a good way to do it in any case.  With the need to do this so many times, it would be great to have it on a keyboard shortcut.  Has anyone been able to do this or something similar?

Comments

  • Tim McCormick
    Tim McCormick Member Posts: 1 ✭✭

    I'm with you!  Have you been able to figure this out in the past 2.5 years, John?

    It looks like no one replied to you.

  • Bradley Grainger (Logos)
    Bradley Grainger (Logos) Administrator, Logos Employee Posts: 12,141

    I haven't tried it myself, but this seems like the kind of problem AutoHotkey may be able to solve: http://www.autohotkey.com/ 

  • John Duffy
    John Duffy Member Posts: 591 ✭✭✭

    I use AutoHotkey for other shortcuts, and it is great.  But if my memory is correct, having tried that (as well as a Word Macro, in VBA), the problem was  in identifying what keystrokes could be used to do so in code.  That is, how to activate the right-click menu and navigate through it to the desired item under 'Additional Actions'.  Getting the right sequence of commands was the problem, as one or more were not available for code implementation.  Yet, that might be down to my lack of programming ability (or ability to search on the web for solutions!), and it might still be technically feasible.

    It's not a big matter, by any means, but with lots of repetitive actions in Word, it would have been great to be able to automate it using a function key or similar.

  • John Duffy
    John Duffy Member Posts: 591 ✭✭✭

    I came across a solution to this the other day.  Instead of a one-button macro solution, a keyboard shortcut works instead. 

    If I highlight a verse reference in a Word document, then press shift+F10, then press a, then press b, the desired verse is shown in Logos Copy Verses. 

    Now all I need is a 'reliable' keyboard method to 'Copy and Paste' into Word without having to use my mouse.  Unfortunately, alt+p doesn't always work in Logos if the focus is in the wrong place in Logos beforehand. But that's a minor quibble.  I'm just pleased to be able to copy and paste verses now without having to right-click on the text.

  • Pieter J.
    Pieter J. Member Posts: 533 ✭✭

    Good Day,

    Be Blessed, although very long after the initial post!

    1. This script make use of AutoHotKey, LogosComApi and Internet Explorer
    2. Open the Script file and Edit line 11 to your preferred language
    3. Run the script
    4. Select a Reference that is replacable in any Application:
      1. Win + B : will replace the selected Reference with Bible Text
      2. To set the style Press Ctrl+Alt+B and set the Preffered style in the Copy Bible Verses dialog. Then close it. Retry 3.1 to see the result
    5. If Bible text or a paragraph contains to many line-feeds, select it:
      1. Ctrl + R  : will remove the line-feeds from selected text and combine it into one paragraph.
    6. If you have text in a foreign language and want to translate it to your own default language, select it:
      1. Ctrl + T  : will translate the selected text to your preferred language

    This is very usefull to me and I use it a lot in Sermon Editor to replace long Psalms with a single paragraph to make it manageable in printouts. I also translate Sermon Outlines copied from Sermon Starter Guide to Sermon Editor.

    6786.CopyBibleVerses.zip

    15
  • John Duffy
    John Duffy Member Posts: 591 ✭✭✭

    Pieter said:

    Good Day,

    Be Blessed, although very long after the initial post!

    1. This script make use of AutoHotKey, LogosComApi and Internet Explorer
    2. Open the Script file and Edit line 11 to your preferred language
    3. Run the script
    4. Select a Reference that is replacable in any Application:
      1. Win + B : will replace the selected Reference with Bible Text
      2. To set the style Press Ctrl+Alt+B and set the Preffered style in the Copy Bible Verses dialog. Then close it. Retry 3.1 to see the result
    5. If Bible text or a paragraph contains to many line-feeds, select it:
      1. Ctrl + R  : will remove the line-feeds from selected text and combine it into one paragraph.
    6. If you have text in a foreign language and want to translate it to your own default language, select it:
      1. Ctrl + T  : will translate the selected text to your preferred language

    This is very usefull to me and I use it a lot in Sermon Editor to replace long Psalms with a single paragraph to make it manageable in printouts. I also translate Sermon Outlines copied from Sermon Starter Guide to Sermon Editor.

    6786.CopyBibleVerses.zip

    15

    Hi Pieter,

    That works just great. That will save much time. Thank you very much.

    It even works when drafting an email in Outlook and when drafting text messages using my keyboard when my mobile is connected to the PC. And the undo (Ctrl+Z) works to change it back too. 

    It is far better than my recent workaround which was to use the keyboard instead of right-clicking on the mouse to use the copy Bible verse Word addin (although the 3 x Tab only works if the focus is on the right place initially in Logos) Shift+F10, A, B, Tab, Tab, Tab, Return.

    The Ctrl+T works great too, as I often have to translate some text, and Google translate is often a good starting point (while it generally needs a quick check by someone more fluent in the language too). It even works on webpages, including the Google search box.

    Many thanks.

    Thank you so much. 

  • Pieter J.
    Pieter J. Member Posts: 533 ✭✭

    Hi John,

    I'm so glad that I could help out. I decided to optimize the script for you, never thought it would be useful to someone else, therefore never improved on it. The script is now more readable and replacement is much faster, almost immediately. You can also easily define your own Hotkey for each function - see the section - Define Hotkeys. If you need any other automation I would be glad to assist if possible.

    2311.CopyBibleVerses.zip

    13
  • John Duffy
    John Duffy Member Posts: 591 ✭✭✭

    Pieter said:

    Hi John,

    I'm so glad that I could help out. I decided to optimize the script for you, never thought it would be useful to someone else, therefore never improved on it. The script is now more readable and replacement is much faster, almost immediately. You can also easily define your own Hotkey for each function - see the section - Define Hotkeys. If you need any other automation I would be glad to assist if possible.

    2311.CopyBibleVerses.zip

    13

    Hi Pieter,

    What can I say, but thank you once again. That is great. I'm sure a lot of other users will find it a real help too. The Define Hotkeys at the start of the script is helpful too. 

    Can I suggest that you add it to the wiki here: https://wiki.logos.com/Tools_and_Files_supplied_by_users

    Thank you once again for this time-saving script that works in so many programs, not just Word.

  • John Duffy
    John Duffy Member Posts: 591 ✭✭✭

    Hi Pieter,

    I was having a little difficulty using this the other day. Sometimes it came up with the error "Your selection doesn't seem to be a Bible Reference" when what was highlighted was clearly a Bible verse. At other times it simply didn't do anything. Logos was running each time I tried this.

    I wonder, is there a program startup sequence which I need to follow? Do I need to have Logos running before I launch the AHK file, or vice versa? I launch my AHK files at startup, and I launch Logos when needed after that. Is that a problem?

  • Pieter J.
    Pieter J. Member Posts: 533 ✭✭

    Hi John,

    Thanks for informing me of this bug.

    The script attach itself to Logos using the LogosComApi. This means it always start Logos when the script runs for the first time. I never shut down Logos or the Script therefore I didn't notice the bug.

    If the script is running and you shut down Logos and/or restart Logos the script doesn't update to the new instance of Logos. This is due to bad error handling on my side.

    Some techincal info: At startup Line 26 jumps to line 32 (GetLogos). When the script is running and you shut down Logos, with the script still running, the script jumps from the hotkey Win + B to line 52, skipping the GetLogos jump in line 26. The fix would possibly be to check if the Logos Application is attached each time Line 52 (CopyBibleVerseAction) executes. I added Code to Line 57 and 58 to do this -

    57 If (!App)
    58    gosub GetLogos

    This should fix the issue - if not, please let me know then I'll try and rethink the code again. The code would now behave a little bit differently: When it looses the Logos instance you will see the Logos Startup Screen if it needs to re-attach to Logos Bible Software. This mean that even if you shut down Logos and the script is running, Win + B will trigger a Logos startup.

    [I] 1067.CopyBibleVerses.zip

    23
  • Pieter J.
    Pieter J. Member Posts: 533 ✭✭

    The bug is bigger than I thought, I'll fix it and post the working update.

    15
  • John Duffy
    John Duffy Member Posts: 591 ✭✭✭

    Pieter said:

    The bug is bigger than I thought, I'll fix it and post the working update.

    15

    Thanks for looking at it.

    I know a little programming, not enough to program but enough to have a bit of an idea of what I'm looking at sometimes. Instead of trying to automatically launch Logos again within the app, if ~B is used some time later after Logos has been closed, how about just using the message box to ask the user to check not only the syntax of the reference, but also to check if Logos is running, and if necessary to launch Logos and reload the script and try again. 

  • Pieter J.
    Pieter J. Member Posts: 533 ✭✭

    That's a great idea. I discovered the bug and it seems to be a bit beyond my range of knowledge of ahk. I'll design a workaround tomorrow in my thoughts and then code it as soon as possible. The problem is that the App variable holding Logos doesn't get released when Logos is Exiting. This restrickt me in validating the variable with if !App before attatching to launcher.application

  • John Duffy
    John Duffy Member Posts: 591 ✭✭✭

    Pieter said:

    That's a great idea. I discovered the bug and it seems to be a bit beyond my range of knowledge of ahk. I'll design a workaround tomorrow in my thoughts and then code it as soon as possible. The problem is that the App variable holding Logos doesn't get released when Logos is Exiting. This restrickt me in validating the variable with if !App before attatching to launcher.application

    Yes, I had experimented with commenting out the first GetLogos and moving the !App and GetLogos in the #B section to just after the msgbox, but it didn't work, for the reason which you have outlined. Knowing how it works helps know how best to use it. But it works great now that I know. 

    Thanks again for this great script.

  • Pieter J.
    Pieter J. Member Posts: 533 ✭✭

    Several things fixed:

    1. I removed the SingleInstance directive and force my own Instance through code. This does not prevent the script to have more than one instance running, it only ensures one instance if the script starts itself.
    2. ClipWait breaks Win + B on the third time I restart Logos, so I removed all code for ClipWait. I placed it on line 56.
    3. The script now completely restarts itself (on Win + B) when Logos is not running to ensure that all variables are released and reloaded. This cause the script to start Logos automatically if not running and Win + B is pressed.
    4. If the script is running and Logos get closed, there is a time-frame in which the script thinks that Logos is still open. This will be visible when Win + B fails to replace a reference in this time-frame. Just wait a few seconds and try Win + B again - the script will then start Logos and replace the reference and function normally.

    I hope this is all and that I didn't miss some other bugs.

    [I] 7774.CopyBibleVerses.zip

    78
  • John Duffy
    John Duffy Member Posts: 591 ✭✭✭

    Pieter, thank you once again. This is a great script. Love it. Thanks for your hard work on it. I hope others find it helpful too for working in Word or any other Windows based program.