Jump to content

Scripting/Automation and Accordance


JakeFromRutgers

Recommended Posts

I am looking into purchasing Accordance, and I was wondering if the following is easily done:

 

I understand that, with the proper modules and whatnot, if I were to type a word or phrase in Hebrew into Accordance, I could get a lot of information about other times when that word or phrase was used - what texts, chapter/verse, etc., even other forms of the word based on its root letters. Is it possible to automate this process? For instance, if I had an exceedingly large number of words or phrases to look up, could I perform searches programatically and collect the results in a file? (In programmer parlance, does Accordance have an API? I could not find one via Google searches.)

 

The actual programming of such a script is not an issue, I am merely wondering if such a thing is possible.

Link to comment
Share on other sites

--Paging Joe Weaks--

 

Jake, this is not my area of expertise in Accordance, but it is Joe's. I think the answer is yes, because he put together an impressive post (video?) along these lines. If I can find it, I'll post it here. Otherwise, he's sure to be around soon....

Link to comment
Share on other sites

Here is Joe's post on "batch searching":

 

http://macbiblioblog.blogspot.com/2013/03/batch-searching-in-accordance-bible.html


(I realize this is different than what you're asking about, but Joe could speak to how to possibly use scripts to see whether what you're asking about is doable.)

Link to comment
Share on other sites

It appears that this method is more of a "macro" than a program - simulating a user's ability to copy and paste the search terms and the results. This is perfectly acceptable, and was my backup plan if there was no other option. I was just wondering if there was a more programmatic option (hence my reference to an API) where the Accordance programmers may have allowed a user to actually send the whole list of queries to the program, and receive back the results, as opposed to copying and pasting each query and then copying and pasting each result. If anyone is aware of such a feature, please let me know. If not, I will definitely use this method. Thank you!

Link to comment
Share on other sites

Hi, Jake,

 

Accordance has only 1 API function (with 3 supporting API's). You can send a text verse reference along with a module name, and the value returned is the full text of the reference. There is no API for "word" searching.

 

The link Abram provided is a proof-of-concept for collecting the kind of data you're talking about, using Applescript UI scripting, which you could bridge with in whatever language you use.

Link to comment
Share on other sites

  • 2 weeks later...

Sorry for the long delay in reply, and thank you to everyone who responded! Joe, did you post the Applescript anywhere so that I can work with it?

Link to comment
Share on other sites

Jake,

Search for Accordance Script Library.

It is a library of handlers for use with a set of Quicksilver Actions and a set of Automator Services, among other things.

Perusing the core library, you'll find those APIs I spoke of, as we all handlers for UI Scripting Accordance.

Those can be used to build any batch paste/search/copy/collect/repeat routine you'd like to cook up.

Using keyboard commands to navigate around Accordance windows/zones/panes/search boxes is part of the tricky part. If you lay out the workflow you're trying to do, I'd be happy to give suggestions... I've been UI scripting Accordance for a looooong time.

Link to comment
Share on other sites

  • 1 month later...

Joe, would it be possible to get your contact information? I have a question regarding some keyboard shortcuts and planning for this that I would like to go over with you if you have 5 minutes.

Link to comment
Share on other sites

Yep. You can email my first and last name with no space between at gmail.

It still might benefit others is you post in the forum. Depends on what your thing is.

Link to comment
Share on other sites

That's a good idea, I'll post my question here. Thanks for your help!

 

I think I've got what I'm trying to do down, although I could use some help with the execution (and planning, if you notice a problem!). Basically, I'm comparing two documents - I have everything set up the way I want it using the Infer command. The Infer command compares Document A to Document B. Document A then gets highlighted in red everywhere that the command finds a match. You then have to select that match in Document A, right click, click on "View Searchback" (or something similar, I don't have Accordance in front of me right now unfortunately), and then a new window will open showing you only the relevant verses from Document B.
Now I'd like to do that with every match from Document A, and copy it all into a large document from which I can see every match.
So here are the steps which I've outlined:
  1. Move to next (first) red-highlighted match in Document A (is it possible to move from one match to the other via keyboard commands?)
  2. Copy entire verse, including verse number
  3. Switch into Word or Notepad or something, paste, skip a line
  4. Back in Accordance, right click match, click "View Searchback"
  5. Copy entire "searchback" window containing the match from Document B
  6. Switch into Word or Notepad, paste, skip two lines
  7. Back in Accordance, exit the new "searchback" window, returning you to Document A
And then repeat.
What do you think?
Link to comment
Share on other sites

Hi Jake,

out of my league here, but re your q1.

 

from the help at file:///Applications/Accordance%20Aleph.app/Contents/Resources/Accordance%20Help/Default.htm#topics/10_ref/kb/navigating_wrkspcs_zones_tabs_panes.htm

 

Ctrl+Cmd+ Go to previous mark

Ctrl+Opt+ Go to next Mark

Edited by Ken Simpson
Link to comment
Share on other sites

Jake,

 

Today, I just did something very similar to what you've described above. Here is what I did instead. I wrote a perl script to take the verse numbers from the 66 chapters of Isaiah, and stored those into an array. Then I simply iterated over the array n times of verses, with an addition \r (MacRoman) return. I had done this previous with collating both B19A and Aleppo, so I had the text I needed. Then I wrote a Macro to manipulate Accordance and paste out the results under verse head. Output being as such:

 

>Isaiah 1:1

  • B19A חֲזוֹן֙ יְשַֽׁעְיָ֣הוּ בֶן־אָמ֔וֹץ אֲשֶׁ֣ר חָזָ֔ה עַל־יְהוּדָ֖ה וִירוּשָׁלִָ֑ם בִּימֵ֨י עֻזִּיָּ֧הוּ יוֹתָ֛ם אָחָ֥ז יְחִזְקִיָּ֖הוּ מַלְכֵ֥י יְהוּדָֽה׃
  • Aleppo א] חֲזוֹן֙ יְשַֽׁעְיָ֣הוּ בֶן־אָמ֔וֹץ אֲשֶׁ֣ר חָזָ֔ה עַל־יְהוּדָ֖ה וִירֽוּשָׁלִָ֑ם בִּימֵ֨י עֻזִּיָּ֧הוּ יוֹתָ֛ם אָחָ֥ז יְחִזְקִיָּ֖הוּ מַלְכֵ֥י יְהוּדָֽה]
  • ‏חזון ישעיה בן א[מוץ אשר חזה על יהודה וירושלם בימי עזיה]‏ויותם אחז ו֯י֯[חזקיה מלכי יהודה -- ]‏[י]שע[יה ]נבא ע[ל יהודה וירושלם -- ] (3Q4 f1:1–3 QUMRAN)
  • הנ[ב]ו֯אוׄת֯[ -- ]שׄ י֯[ -- אשר חזה על יהודה] (4Q165 f1_2:1 QUMRAN)
  • [1] [כול בני ישראל בכול מושבותיהמה לפני יהוה חוק עולם] [2] [לדורותיהמה. [[ ? ]]] [3] [ואחר מועד היצהר יקריבו למזבח את העצים שנים] [4] [עשר מטות בני ישראל. והיו המקריבים ביום הרישון מטות] [5] [לוי ויהודה וביום השני בנימין ובני יוסף יחד אפרים] (11Q19 23:0 QUMRAN)
  • 11Q20 6:13‏ מטות֯[ לוי ]ויהודה ובׄ[יום השני בנימין ובני יוסף וביום השלישי ראובן ושמעון]

Let the bullet = tab.

 

This is rather broad search as the INFER argument was set to 5,1,1. This is because I am working from a broad definition of what 'quote' might mean, and narrowing down based on case by case to account for scribal approaches.

Link to comment
Share on other sites

Couple points of clarity:

Are you wanting to collect just the INFER and the SEARCH BACK verse references, or the text from each?

Are you wanting to run the SEARCH BACK on the verse reference or on the MARKED HIT PHRASE from each verse?

 

As James hints at, one thing you could do is reduce the steps in your macro, by getting the verse list from your INFER command, and using that list to then do the iterations. That is for doing a verse Search Back (I think of it as a reverse INFER), using verses, but not the Marked words.

 

However, actually copying from Accordance's original INFER tab (tab #2) and pasting in a word processor, and copy and pasting from the Search Back tab (tab #4), you have the benefit of keeping the formatting with the marked words. This is more cumbersome to accomplish. The main problem is "selecting a result/marked words" the INFER tab (tab #2) and running the search back from it. The problem is that Accordance keyboard navigation is pretty limited in the text pane. There's a draw bug with the insertion point, and there's not a programmatic way to select marked words. So, out of the gate, you're stuck doing the Search Back command on the verse reference. Even still, there's no reliable way to programmatically set the insertion point in front of a verse, then in front of the next verse, etc. All the move up down one verse/marked verse simply scroll the window but do NOT change the insertion point position. In ancient days, there was a key combo that moved the insertion point to position 0 in the view, but it was lost.

Still, something like this is doable. I can think of a way to get data that only needs to be cleaned up a little.

I'll post something later.

Link to comment
Share on other sites

I went ahead and worked out a solution to share, the point of which is to demonstrate to you guys the wide breadth of what is possible for collecting data.

The big problem here is programmatically making the selection you want in order to do the Search Back, then selecting the next verse.

This imperfect solution has you turn off text width limits, reduce the font size of the initial INFER window and suppress poetry, all in an attempt to keep each result verse on one line. Some stuff gets cut off when they do wrap still.

 

I put a demo video on my blog you can find here.

 

And here's the code. The flow is heavily commented, so you can follow it and learn how to do your own.

-- Collect INFER and Search Back results in Accordance
property textApp : "TextEdit" -- name of your word processor or text editor
set d to 0 -- set global delay to 1 or more to observe the process, for troubleshooting purposes
set r to 100 -- max number of verses to iterate through

-- start the script with insertion point in Accordance in position 0, in front of the first marked verse of the INFER source tab (tab2) in the text window

set n to 1 -- counter for searches
set sourceVerse to ""
repeat r times
    tell application "Accordance" to activate
    delay 0.1
    delay d
    tell application "System Events"
        tell process "acord"
            click menu item "Search Back Linked Text" of menu 1 of menu bar item "Amplify" of menu bar 1
            delay 1
            -- Accordance moves to tab4
            
            -- Check Search Back results Search Criteria to make sure an errant string search was not conducted
            key code 123 -- left arrow to collapse any selection
            keystroke tab -- highlight search box
            keystroke "c" using {command down} -- copy Search Back search criteria
            delay 0.3
            delay d
            set searchBackCriteria to the clipboard -- save Search Back search criteria to variable
            
            -- go to source tab
            keystroke tab using {control down} -- go to tab1
            keystroke tab using {control down} -- go to tab2
            delay d
            key code 124 using {shift down, command down} -- Cmd Shft Rt to select entire source verse
            delay d
            keystroke "c" using {command down} -- copy
            delay 0.3
            delay d
            set previousSourceVerse to sourceVerse
            set sourceVerse to the clipboard
            delay 0.1
            
        end tell
    end tell
    
    if sourceVerse = previousSourceVerse then
        display dialog "Last source verse searched:" & return & sourceVerse
        exit repeat -- would just be repeating the last Source Verse
    end if
    
    if word 1 of searchBackCriteria is "INFER" then -- a valid Source Verse was used for the Search Back result (i.e. did not search for a word from a wrapped line)
        
        -- paste the Source Verse in a word processing app or text editor
        tell application textApp to activate
        delay 0.1
        delay d
        tell application "System Events"
            tell process textApp
                keystroke return
                keystroke (n as string) -- add a iteration notation for each new entry
                keystroke " =========="
                keystroke return
                delay d
                keystroke "v" using {command down} -- paste source verse
                delay 0.3
                delay d
                key code 124 -- right arrow collapse selection
                keystroke return
                keystroke " --------"
                keystroke return
                delay d
            end tell
        end tell
        
        tell application "Accordance" to activate
        delay 0.1
        delay d
        tell application "System Events"
            tell process "acord"
                -- go to the results tab
                keystroke tab using {control down} -- go to tab3
                keystroke tab using {control down} -- go to tab4
                delay d
                
                -- go copy the results
                keystroke tab using {option down, shift down} -- place insertion point in the text pane
                delay d
                keystroke "a" using {command down} -- select all
                delay 0.1
                delay d
                keystroke "c" using {command down} -- copy Search Back results
                delay 0.3
                delay d
                
                -- go to the source tab
                keystroke tab using {control down} -- go to tab1
                keystroke tab using {control down} -- go to tab2
                delay d
                
            end tell
        end tell
    end if
    
    -- Accordance is already front app
    tell application "System Events"
        tell process "acord"
            -- prepare the Accordane window for the next verse search
            key code 125 -- down arrow to go to the next verse
            -- sometimes this will go to the next LINE of a single wrapped verse, but not always
            delay d
            key code 123 using {command down} -- Cmd left arrow to put insertion point at beginning of line
            delay d
        end tell
    end tell
    
    tell application textApp to activate
    delay 0.1
    delay d
    tell application "System Events"
        tell process textApp
            keystroke "v" using {command down} -- paste Search Back results
            delay 0.5
            delay d
            keystroke return
            delay d
            delay d
            set n to n + 1
        end tell
    end tell
end repeat
Edited by Joe Weaks
Link to comment
Share on other sites

Hi Joe,

 

Cool script. Couple of questions about synchronization and delay given how much delay is used above - some is your debug (delay d) but others are there all the time. I've been GUI scripting Acc for a few purposes and I have noticed instability which I have put down to the asynchronous nature of AppleEvents processing. I'll explain what I've seen and ask what you think.

 

When GUI scripting I've noticed that if there is no delay in the script, especially at certain points, the script can intermittently fail - you end up trying to operate in the wrong tab or pasting no data, or a file isn't where it should be when it should be and so on. For example if you have a bunch of text results to copy out of a pane you can benefit from a delay after the cmd-C. You have examples of this above. If you are pasting into another program (eg. an editor) that the paste can take some time and its not the AS script that you wrote that is doing the paste but the program into which you are pasting it. As a consequence you have a problem in knowing when the paste is completed. Sometimes I've been able to back up longer operations with check loops to ensure that the result I'm looking for has occurred but this is not always possible and it complicates the code.

 

I know of no way in which this can be made synchronous and thus not prone to timing issues. Do you ?

 

On a related point have you noticed the issue in delay() calls in iterative scripts where delay(1) might result in a 10 second or longer delay ? I posted a note on that issue a while back. I now try to avoid its use so that iterative scripts don't run for very times. I use a shell call to the OS sleep in its place which is stable and predictable.

 

Thx

D

Link to comment
Share on other sites

Daniel,

Quick and dirty, I used and kept in superfluous delay commands in the script, in part to demonstrate to others where choking might occur.

 

On #1, correct, a copy and past and some UI calls are not synchronous... the script with just keep on trucking, so you have to put a blunt delay in or check for the presence of something. Note: set x to the clipboard is synchronous. The best method of course is to check until you know it's save to move on (if frontmost app is xyz then... if last line of contents is xyz then... if title of button 3 of window 1 is... etc.).

Note that I'm using cut and paste here in order to preserve the bold hits. If that is not necessary, then by all means, don't use paste. set the clipboard to a variable and insert it, even in a text file with write to file (or a shell call since you like to do that).

 

On #2, yes, I have in Mavericks seen a lag effect on using delay in iterative scripts. Others have too. Just google 'mavericks applescript delay' and you'll find lots of forum chatter about the bug. As you mentioned, there are other shell solutions to avoid delay.

Link to comment
Share on other sites

Thanx Joe - yep all makes sense and is what I've seen. I figured the C&P was for the highlighting. I didn't realize the delay issue was peculiar to Mavericks as I'd seen what I thought were older posts on it around the place. Writing to a file is fine but when you ask Acc to write to a file you have a problem checking the completion - currently I use a larger delay - I'll check out the "last line of contents of" and see if that helps me here.

 

On sync thing : you say some UI calls are async. I would have expected that pretty much any tell app "System Events" to tell Acc .... will be async even though they might be quick. Is this not always so ? If not then I'm not following yet how the AS -> Sys Ev -> target app messages are built and sent. I'll have to hunt that up.

 

I'm still trying to come up with some general coding guidelines here for how to do all this stuff so that the execution is robust. Its just not as solid as I'd like yet.

 

Thx

D

Link to comment
Share on other sites

Daniel, you're right, I was being sloppy. All GUI tells are async of course.

I could also be wrong about the delay bug being just Mavericks.

 

On checking whether a file is saved, don't forget: if newFile exists...

Link to comment
Share on other sites

Ah ok thanx Joe. I might also be misremembering regarding delay as there was also a CPU issue in delay in pre-Mav releases. Anyhow not to worry - w/a available.

 

Thx

D

Link to comment
Share on other sites

Hi Joe, thank you so much for your help. I'm running into a number of issues, so I made a video so that perhaps you can help. My goal is to compare the Hebrew Book of Ben Sira to the Hebrew Proverbs. I'm very confused as to what I'm supposed to be doing within Accordance to get the results I want: A Word document containing a Ben Sira verse followed by a Proverbs verse, with their matching words highlighted. I unfortunately can't use your script because I'm working in Windows, but that's fine, this should help both my understanding and anyone else's understanding if they read this post.

 

Video: http://youtu.be/6wySqUEKeMk

 

I ran into a number of crazy things - issues with Accordance, issues with the interface, etc. Many of them are probably me misunderstanding what I'm trying to do. However, not all of them are, and I'd really like to get this running as soon as possible. I would really appreciate any help you can give me!

Link to comment
Share on other sites

Hi Jake,

 

I didn't know you were on a PC, so much of my effort was pointless. I need to learn to remember that I can no longer assume Accordance users are Mac users.

 

I watched the video. First order of business is to get the INFER and Search Back working for you manually, before then attempting the automation.

(To that end, it might have been good to post some of those 'how to get it to work' questions as a separate topic. Most forum users are ignoring this topic case it has a techy-geeky topic title they assume will be over their head. I've not used the INFER command a lot, so a broader set of eyes would help you.)

 

Let me say Jake, by watching your video, I can see you're doing a great job learning things, and already have a command of the program beyond many who've used it for much longer.

 

I'll try and address some of the INFER use probs and then move on to gameplay for automation, but some of what you showed it buggy behavior that I am guessing in just on the windows version, which I've never seen. Those problems selecting Hebrew that has English on the same line have always annoyed me (yes, I do read a bit of Hebrew).

 

When you run INFER, the resulting window can be configured to display each verse per line using menu item

/Display/Set Text Pane Display…

You can do the same for each result window.

 

Now, as for the Search Back command:

Just to clarify, you can run Search Back either on a selection of word(s), or on the verse. So when you saw me selecting just prior to or inside the verse, I was running a verse Search Back. When you run a Search Back on the verse, it opens a third tab and a fourth tab. It does this so it can isolate the selected verse and then search for that in Tab3, so that Tab4 can use it to run: [iNFER 5 CEB 3] <AND> [CONTENTS CEB]

So, that tab is not 'useless'... it is a penultimate step in getting at tab4, when you are searching whole verses. Cause, when you search back for a whole verse, it simply runs an INFER command on that verse, and your original source text (as you can see in the search criteria in tab4.

 

Now, when you Search Back from a selected phrase (presumably the red highlighted results from your INFER search), it doesn't need that intermediate tab3, cause the search criteria to Search Back in that case is: phrase I have selected <AND> [CONTENTS CEB]

You can see this behavior by only having your original 2 tabs open, and run Search Back from a selected phrase, and see that it will only open 1 tab. Note that if you had a tab3 AND tab4 opened up from previously Searching Back for a whole verse, that tab3 won't update or change while you do a phrase Search Back.

Note also that the phrase Search Back command will add a "[fuzzy 3]" in there, too, if a word in the phrase is not highlighted.

 

 

Understanding how all that works is vitally important for you to understand my forthcoming suggestion about how to achieve results programmatically. Because, you're going to need to overcome some of Accordance scriptablity limitations by massaging the source material elsewhere.

The real problem is there's no way to reliably select some text in the text pane of the Tab2, in order to then run Search Back on it. (I nearly achieved it by putting each verse on one line and shrinking it as much as possible to reduce the line wraps. But, if you're wanting to run Search Back on just the red highlighted phrase, you are out of luck doing it within Accordance.

But... who cares.

If you want to compile the results based on phrase, here's what I would suggest.

 

1. Set up your window with the 3 tabs... All Proverbs | Ben Sira INFER results | Proverbs Search Back Results

(Get the third tab by Searching Back for a selected phrase, not the verse reference.)

 

2. Copy the Ben Sira results from tab2 and paste it into a Word document.

 

3. Make note of the search criteria in the Proverbs search back tab3. It'll be something like:

בְּ י֥וֹם צָרָ֗ה <AND> [CONTENTS All Proverbs]

(The English and Hebrew portions may be swapped in the browser window)
Leave this Tab3 Search back results in the front.

4. Go back to your Word document, that has the verses with highlighted phrases in Ben Sira. Use this document as your search_phrase source, instead of trying to pull it from tab 2 of Accordance. Use VBA to select the next bold or red phrase, then process it in Accordance, then paste results in another document.

Pseudo code would be something like:

 

search_phrase = result of VBA select next font.bold phrase

 

search_string = search_phrase + "<AND> [Contents All Proverbs]"

 

bring Accordance to the front

 

Tab # to highlight the search box

 

paste search_string # to place the search string

 

keystroke return # to initiate the search

 

keystroke Alt-Shift-Tab # to place cursor in the text pane

 

Select all

 

Copy

 

Bring results Word document to the front

 

Paste the result

 

Go to source Word document

 

Select the whole verse of the phrase you selected

 

Copy that verse

 

Go to result Word doc to paste it

 

Add your "========" divider

 

return to your Word source document

 

Repeat

 

</end code flow>

 

I've done this type of culling a word document in VBA to pull phrases that are bold.

What I don't know, and can't help with is how you are doing key macros in Accordance. Accordance for Windows has no COM bindings or anything, so I assume you're using a macro keyboard program.

Link to comment
Share on other sites

Hey Jake,

 

I've only just cracked the surface of this but I was looking into scripting Acc on win and I'm playing with AutoIt. I have done very little but I can get it to pop a specified workspace to the front and enter search text and execute a simple search with it.

 

Thx

D

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...