Jump to content


Photo

Scripting/Automation and Accordance


  • Please log in to reply
23 replies to this topic

#1 JakeFromRutgers

JakeFromRutgers

    Member

  • Active Members
  • Pip
  • 12 posts
  • Accordance Version:10.x

Posted 09 December 2013 - 08:35 AM

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.



#2 Abram K-J

Abram K-J

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,483 posts
  • Gender:Male
  • Location:Greater Boston, MA
  • Accordance Version:10.x

Posted 09 December 2013 - 08:52 AM

--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....


Abram K-J
Pastor, Writer, Freelance Editor, Youth Ministry Consultant, Blogger
Web: Words on the Word


#3 JakeFromRutgers

JakeFromRutgers

    Member

  • Active Members
  • Pip
  • 12 posts
  • Accordance Version:10.x

Posted 09 December 2013 - 08:54 AM

Amazing, thank you!



#4 Abram K-J

Abram K-J

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,483 posts
  • Gender:Male
  • Location:Greater Boston, MA
  • Accordance Version:10.x

Posted 09 December 2013 - 08:59 AM

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

 

http://macbiblioblog...ance-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.)


Abram K-J
Pastor, Writer, Freelance Editor, Youth Ministry Consultant, Blogger
Web: Words on the Word


#5 JakeFromRutgers

JakeFromRutgers

    Member

  • Active Members
  • Pip
  • 12 posts
  • Accordance Version:10.x

Posted 09 December 2013 - 09:21 AM

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!



#6 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,043 posts
  • Gender:Male
  • Location:Raytown, MO (outside KC)
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:8.x

Posted 09 December 2013 - 11:20 AM

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.


Joe Weaks
The Macintosh Biblioblog

Sometimes I'm so helpful even I can't stand it.

#7 JakeFromRutgers

JakeFromRutgers

    Member

  • Active Members
  • Pip
  • 12 posts
  • Accordance Version:10.x

Posted 20 December 2013 - 03:18 PM

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?



#8 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,043 posts
  • Gender:Male
  • Location:Raytown, MO (outside KC)
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:8.x

Posted 20 December 2013 - 10:44 PM

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.


Joe Weaks
The Macintosh Biblioblog

Sometimes I'm so helpful even I can't stand it.

#9 JakeFromRutgers

JakeFromRutgers

    Member

  • Active Members
  • Pip
  • 12 posts
  • Accordance Version:10.x

Posted 28 January 2014 - 11:16 AM

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.



#10 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,043 posts
  • Gender:Male
  • Location:Raytown, MO (outside KC)
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:8.x

Posted 28 January 2014 - 02:46 PM

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.


Joe Weaks
The Macintosh Biblioblog

Sometimes I'm so helpful even I can't stand it.

#11 JakeFromRutgers

JakeFromRutgers

    Member

  • Active Members
  • Pip
  • 12 posts
  • Accordance Version:10.x

Posted 28 January 2014 - 10:08 PM

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?


#12 Ken Simpson

Ken Simpson

    Platinum

  • Accordance
  • 1,334 posts
  • Gender:Male
  • Location:Sydney, Australia
  • Interests:Astronomy
    Archaeology
    Physics
    Hebrew and Greek
    Papyrology
    Surgeon
  • Accordance Version:10.x

Posted 28 January 2014 - 10:16 PM

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, 28 January 2014 - 10:44 PM.

Regards
Ken
Australian Accordance Demonstrator

Administrator, Accordance Exchange

Assistant Minister, Summer Hill Church


#13 JakeFromRutgers

JakeFromRutgers

    Member

  • Active Members
  • Pip
  • 12 posts
  • Accordance Version:10.x

Posted 28 January 2014 - 10:33 PM

Thanks Ken!



#14 James Tucker

James Tucker

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 644 posts
  • Gender:Not Telling
  • Accordance Version:10.x

Posted 28 January 2014 - 11:45 PM

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.



#15 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,043 posts
  • Gender:Male
  • Location:Raytown, MO (outside KC)
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:8.x

Posted 29 January 2014 - 10:38 AM

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.


Joe Weaks
The Macintosh Biblioblog

Sometimes I'm so helpful even I can't stand it.

#16 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,043 posts
  • Gender:Male
  • Location:Raytown, MO (outside KC)
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:8.x

Posted 29 January 2014 - 06:06 PM

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, 29 January 2014 - 07:29 PM.

Joe Weaks
The Macintosh Biblioblog

Sometimes I'm so helpful even I can't stand it.

#17 Daniel Semler

Daniel Semler

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,178 posts
  • Gender:Male
  • Accordance Version:10.x

Posted 30 January 2014 - 11:16 AM

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


Accordance Configurations :

 

Mac : 2009 27" iMac                 Windows : HP 4540s laptop

      Intel Core Duo                          Intel i5 Ivy Bridge

      12GB RAM                                8GB RAM

      Accordance 10.4.3.2                     Accordance 10.4.3.2 and Aleph 10.4.3.2

      OSX 10.9 (Mavericks)                    Win 7 Professional x64 SP1


#18 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,043 posts
  • Gender:Male
  • Location:Raytown, MO (outside KC)
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:8.x

Posted 30 January 2014 - 12:46 PM

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.


Joe Weaks
The Macintosh Biblioblog

Sometimes I'm so helpful even I can't stand it.

#19 Daniel Semler

Daniel Semler

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,178 posts
  • Gender:Male
  • Accordance Version:10.x

Posted 30 January 2014 - 01:56 PM

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


Accordance Configurations :

 

Mac : 2009 27" iMac                 Windows : HP 4540s laptop

      Intel Core Duo                          Intel i5 Ivy Bridge

      12GB RAM                                8GB RAM

      Accordance 10.4.3.2                     Accordance 10.4.3.2 and Aleph 10.4.3.2

      OSX 10.9 (Mavericks)                    Win 7 Professional x64 SP1


#20 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,043 posts
  • Gender:Male
  • Location:Raytown, MO (outside KC)
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:8.x

Posted 30 January 2014 - 02:30 PM

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...


Joe Weaks
The Macintosh Biblioblog

Sometimes I'm so helpful even I can't stand it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users