Jump to content

Script for Multi-version Verse Lookup


Joe Weaks

Recommended Posts

Here is a script that will take a valid verse reference and return the text of the reference for every relevant module you have installed in Accordance.  (As discussed in this topic.)

This edition of the script asks for the reference in dialog box and then displays the result in a new TextEdit document, but the core routine could be adapted in any environment.


-- use a display dialog to ask for valid verse reference

set dd to display dialog "Enter a valid verse reference:" default answer "John 1:1"

set theReference to text returned of dd

multiModuleVerseLookup(theReference, true)

 

on multiModuleVerseLookup(theReference, quoteAsCitation)

-- set the delimiter between versions

set theDelimiter to return & "----------" & return

 

-- get moduleList

tell application "Accordance" to set moduleList to «event AccdVerL»

 

-- prepare textResult

set textResult to theReference & theDelimiter

 

repeat with thisModule in moduleList

-- lookup theReference in each module

tell application "Accordance" to set thisResult to «event AccdTxRf» {thisModule, theReference, quoteAsCitation}

 

-- add the result if the module contains theReference

if thisResult does not start with "ERR-" then set textResult to textResult & thisModule & return & thisResult & theDelimiter

end repeat

 

-- add display the result in a new TextEdit document

tell application "TextEdit"

activate

set textDoc to make new document at the front

set the text of textDoc to textResult

end tell

end multiModuleVerseLookup

 

 

A longer description of the script can be found here on my blog.

 

And, FWIW, I still think it'd be a good idea to have a sub-forum for scripting/automation/Services/siri lookup/etc. 

Edited by Joe Weaks
  • Like 2
Link to comment
Share on other sites

This is awesome! Thank you for working on it and posting it here!

  • Like 1
Link to comment
Share on other sites

Amazing, Thanks!

 

When you make a post, use the tag line to tag "script" and "AppleScript" clicking on a tag allows you to see all related posts.

 

post-33292-0-70961600-1540119053_thumb.png

 

So for example, all LXX posts:

 

https://www.accordancebible.com/forums/tags/forums/LXX/

In my own personal opinion, tagging is more powerful than folders, as it allows categorising a file (aka forum posts) under multiple locations (categories). Sometimes I do forget to tag though.

Edited by Ιακοβ
  • Like 1
Link to comment
Share on other sites

 

-- get moduleList

tell application "Accordance" to set moduleList to «event AccdVerL»

 

 

Should be noted that by changing this line we can narrow down our results to only the texts we pre-select:

 

-- get moduleList

set moduleList to {"KJVS", "NAS95S", "ESVS"}

 

This is a huge help to me! Thanks again!
Edited by OSchrock
  • Like 1
Link to comment
Share on other sites

So, taking the opportunity to learn some more, I've adjusted my previous service to accept multiple text module selections (cmd-click) and multiple verse references (delimited by a semicolon).

 

Here's the script and attached is the service

-- Set variables
set theTexts to {}
set theResults to {}

-- Get available text modules
tell application "Accordance" to set textList to «event AccdVerL»

--Sort list
set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "\n"
set list_string to (textList as string)
set new_string to do shell script "echo " & quoted form of list_string & " | sort -f"
set textList to (paragraphs of new_string)
set AppleScript's text item delimiters to old_delims

-- Create dialog to select text modules
choose from list textList with prompt "What text would you like?" with multiple selections allowed
if the result is not false then
	set theTexts to the result as list
else
	error number -128
end if

-- Get the text(s)
set theResultsText to getText(theTexts, theResults)

-- Send the data to your text file
set the clipboard to theResultsText

activate application (path to frontmost application as text)
tell application "System Events" to tell (1st process whose frontmost is true) to keystroke "v" using {shift down, option down, command down}

-- Get text routine
on getText(theTexts, theResults)
	
	-- Ask for reference(s)
	set refResult to display dialog "Verse Reference (eg John 1:1)" default answer "" buttons {"Cancel", "Without Citation Format", "With Citation Format"} default button "With Citation Format" with icon path to resource "application.icns" in bundle (path to application "Accordance")
	
	-- Process dialog results
	if the refResult is not false then
		set theRefs to theSplit(text returned of refResult, "; ")
		if button returned of refResult is "With Citation Format" then
			set theCitationformat to "true"
		else if button returned of refResult is "Without Citiation Format" then
			set theCitationformat to "false"
		else if button returned of refResult is "Cancel" then
			error number -128
		end if
	end if
	
	-- Get data from Accordance
	if theRefs is not {} then
		-- Get data from Accordance
		repeat with theReference in theRefs
			repeat with theModulename in theTexts
				tell application "Accordance" to set theText to «event AccdTxRf» {theModulename, theReference, theCitationformat}
				if text 1 thru 3 of theText is "Err" then
					copy theModulename & ": The reference (" & theReference & ") does not exist in this resource\n" to the end of theResults
				else
					copy theText & "\n\n" to the end of theResults
				end if
			end repeat
		end repeat
		
		-- Concatenate result list into a single string
		set theResultsText to ""
		repeat with theTrans in theResults
			set theResultsText to theResultsText & theTrans
		end repeat
	else
		display dialog "Please enter a valid verse or set of verses" with icon caution
		getText(theTexts, theResults)
	end if
	
	-- Remove excessive ending newlines
	if theResultsText is not "" then repeat until text -2 of theResultsText is not "\n"
		set theResultsText to text 1 thru -2 of theResultsText
	end repeat
	
	return theResultsText
end getText

-- Split routine
on theSplit(theString, theDelimiter)
	-- save delimiters to restore old settings
	set oldDelimiters to AppleScript's text item delimiters
	-- set delimiters to delimiter to be used
	set AppleScript's text item delimiters to theDelimiter
	-- create the array
	set theArray to every text item of theString
	-- restore the old setting
	set AppleScript's text item delimiters to oldDelimiters
	-- return the result
	return theArray
end theSplit

getRefs.workflow.zip

  • Like 2
Link to comment
Share on other sites

To avoid a typo creating havoc, might also want to add a text size limit like:

if (count of thisResult > 1000) then set thisResult to (text 1 thru 1000 of thisResult)
Link to comment
Share on other sites

 

So, taking the opportunity to learn some more, I've adjusted my previous service to accept multiple text module selections (cmd-click) and multiple verse references (delimited by a semicolon).

 

Here's the script and attached is the service

Hmmm

This one gives me 'The verse 'NIV' is not available to accordance' then accordance crashes!

I love what you are doing though.

Can you post a finished working version?

Link to comment
Share on other sites

FYI the script is not working for me.

I think that's because it's putting a garbage character (see question mark below) in front of the module name that is causing accordance to crash.

I am using Accordance 11.

 

 

«event AccdTxRf» {"?ESVS", "john ", "true"}
Link to comment
Share on other sites

 

FYI the script is not working for me.

I think that's because it's putting a garbage character (see question mark below) in front of the module name that is causing accordance to crash.

I am using Accordance 11.

 

 

«event AccdTxRf» {"?ESVS", "john ", "true"}

 

 

 

Could you show me screen shots of your step by step?

 

Here's mine. These are from the workflow attached to my above post.

 

post-30445-0-89072800-1540430816_thumb.png

post-30445-0-69973500-1540430830_thumb.png

post-30445-0-03743400-1540430843_thumb.png

 

Also, if you could show the text of the textList. I don't see any control characters in my list.

 

Ex: {"AF-E", "AF-L", "AF-T", "AFL-E", "AFL-T", … "ERV", "ESV", "ESVS",  … "UBS4-T", "UBS5-T", "UGAR-E", "UGAR-T", "V-LATINA", "VAMVAS", "VDC2014", "VULG-N", "VULG-T", "VULG2-T", "VULGATE", "WEB", "WEBSTR", "WEYMTH", "WUEST-NT", "YNG", "ZÜRCHER-LEM"}

Link to comment
Share on other sites

Wayne,

Does my simple script error for you? It works for me and I have ESVS installed.

There was a time when I would see a bug in Accordance appleevents where you get the module name from the generated module list and it added a control character that would break the subsequent lookup.

So, I added this cleanup handler to the module name. I think it should be updated to include "-" and "_" and any other legit character that shows up in short names of modules:

set thisModule to my removeExtraCharacters(moduleName)

on removeExtraCharacters(theString)
	-- removes all non-alphanumeric characters from the beginning and the end of the string
	
	set theString to theString as string
	repeat
		if (text 1 thru 1 of theString) is in "abcdefghijklmnopqrstuvwxyz1234567890()" then exit repeat
		set theString to text 2 thru -1 of theString
	end repeat
	repeat
		if text -1 thru -1 of theString is in "abcdefghijklmnopqrstuvwxyz1234567890()" then exit repeat
		set theString to text 1 thru -2 of theString
	end repeat
	return theString
end removeExtraCharacters
Link to comment
Share on other sites

 

There was a time when I would see a bug in Accordance appleevents where you get the module name from the generated module list and it added a control character that would break the subsequent lookup.

 

 

Yes I think that's what's happening.

 

I'll just stick with my script it works!

Link to comment
Share on other sites

  • 1 year later...

Hello Graham,

 

I tried to run the script in ScriptEditor, but it returns an error message:

It highlights "path to resource "application.icns" in bundle (path to application "Accordance")" and says "error "Resource not found." number -192".

 

 

Could you show me screen shots of your step by step?

 

Here's mine. These are from the workflow attached to my above post.

 

attachicon.gifScreen Shot 2018-10-24 at 9.29.47 PM.png

attachicon.gifScreen Shot 2018-10-24 at 9.31.08 PM.png

attachicon.gifScreen Shot 2018-10-24 at 9.31.28 PM.png

 

Also, if you could show the text of the textList. I don't see any control characters in my list.

 

Ex: {"AF-E", "AF-L", "AF-T", "AFL-E", "AFL-T", … "ERV", "ESV", "ESVS",  … "UBS4-T", "UBS5-T", "UGAR-E", "UGAR-T", "V-LATINA", "VAMVAS", "VDC2014", "VULG-N", "VULG-T", "VULG2-T", "VULGATE", "WEB", "WEBSTR", "WEYMTH", "WUEST-NT", "YNG", "ZÜRCHER-LEM"}

 

Link to comment
Share on other sites

This works great!

Thank you so much!

 

Here is a script that will take a valid verse reference and return the text of the reference for every relevant module you have installed in Accordance.  (As discussed in this topic.)

This edition of the script asks for the reference in dialog box and then displays the result in a new TextEdit document, but the core routine could be adapted in any environment.

-- use a display dialog to ask for valid verse reference

set dd to display dialog "Enter a valid verse reference:" default answer "John 1:1"

set theReference to text returned of dd

multiModuleVerseLookup(theReference, true)

 

on multiModuleVerseLookup(theReference, quoteAsCitation)

-- set the delimiter between versions

set theDelimiter to return & "----------" & return

 

-- get moduleList

tell application "Accordance" to set moduleList to «event AccdVerL»

 

-- prepare textResult

set textResult to theReference & theDelimiter

 

repeat with thisModule in moduleList

-- lookup theReference in each module

tell application "Accordance" to set thisResult to «event AccdTxRf» {thisModule, theReference, quoteAsCitation}

 

-- add the result if the module contains theReference

if thisResult does not start with "ERR-" then set textResult to textResult & thisModule & return & thisResult & theDelimiter

end repeat

 

-- add display the result in a new TextEdit document

tell application "TextEdit"

activate

set textDoc to make new document at the front

set the text of textDoc to textResult

end tell

end multiModuleVerseLookup

 

 

A longer description of the script can be found here on my blog.

 

And, FWIW, I still think it'd be a good idea to have a sub-forum for scripting/automation/Services/siri lookup/etc. 

 

Link to comment
Share on other sites

I'm assuming this is a Mac thing!

Is there a comparable Windows thing?

  • Like 1
Link to comment
Share on other sites

I, too, would be interested in extending Accordance functionality on Windows. I'm not familiar with Apple services, script, and architecture. I am familiar with some kinds of programming. Are we talking PowerShell, vbscript, or something like that?? Is Accordance exposed on Windows - API or command-line parameters??

Link to comment
Share on other sites

I have tried to do something similar with AutoIt on occasion. Honestly there isn't such an in-built integration though on Windows. AutoIt, and some other tool I looked at from MS for identifying widgets by name, within an application run into issues uniquely identifying the widgets in Acc. They are not named in a way that makes it easy to navigate or manipulate. Even menu access was not particularly easy. On Mac you can write quite extensive scripts to automate Acc even though there, you will also run into some difficulties. But I have never gotten anywhere on Windows with this, whereas on Mac I could get batch executions running well enough.

 

I would love Accordance to open up a generic API but there are a lot of issues to consider with such a thing.

 

Thx

D

Link to comment
Share on other sites

Sorry folks, this is one of the (very few I'm sure) benefits of being on a Mac.  ^_^

Link to comment
Share on other sites

For those who might be interested, I modified this to suit my preference:

 

1. I deleted the "add display the result in a new TextEdit document".

2. Instead, I use Keyboard Maestro's "Display Text in Window" macro (see screenshot).

3. In order to pass the text to the system clipboard, I need to add one line:

    set the clipboard to textResult

 

This has a few benefits:

A. I can adjust the display font size (first adjust the font size of %SystemClipboard% in a word processor; then paste it to Keyboard Maestro indicated in the screenshot).

B. I can simply close the window after viewing the verses (by hitting either Esc or Enter).

C. I can filter the paragraph sign ¶ before viewing the verses (see screenshot).

D. The text is already in the system clipboard. I can paste to wherever I want.

E. Of course, in Keyboard Maestro I can add more actions.

post-32138-0-12463800-1592512720_thumb.png post-32138-0-81213800-1592512702_thumb.png

 

Here is a script that will take a valid verse reference and return the text of the reference for every relevant module you have installed in Accordance.  (As discussed in this topic.)

This edition of the script asks for the reference in dialog box and then displays the result in a new TextEdit document, but the core routine could be adapted in any environment.

-- use a display dialog to ask for valid verse reference

set dd to display dialog "Enter a valid verse reference:" default answer "John 1:1"

set theReference to text returned of dd

multiModuleVerseLookup(theReference, true)

 

on multiModuleVerseLookup(theReference, quoteAsCitation)

-- set the delimiter between versions

set theDelimiter to return & "----------" & return

 

-- get moduleList

tell application "Accordance" to set moduleList to «event AccdVerL»

 

-- prepare textResult

set textResult to theReference & theDelimiter

 

repeat with thisModule in moduleList

-- lookup theReference in each module

tell application "Accordance" to set thisResult to «event AccdTxRf» {thisModule, theReference, quoteAsCitation}

 

-- add the result if the module contains theReference

if thisResult does not start with "ERR-" then set textResult to textResult & thisModule & return & thisResult & theDelimiter

end repeat

 

-- add display the result in a new TextEdit document

tell application "TextEdit"

activate

set textDoc to make new document at the front

set the text of textDoc to textResult

end tell

end multiModuleVerseLookup

 

 

A longer description of the script can be found here on my blog.

 

And, FWIW, I still think it'd be a good idea to have a sub-forum for scripting/automation/Services/siri lookup/etc. 

 

Link to comment
Share on other sites

I have a question:

There are 31 verses in Gen 1. If I enter Gen 1:50 (or any number larger than 31), it would return the content of Gen 1:31 (the last verse of the chapter) for me.

Is it possible to make the script to give a warning that the reference is incorrect instead of giving the last verse of the chapter?

 

 

Here is a script that will take a valid verse reference and return the text of the reference for every relevant module you have installed in Accordance.  (As discussed in this topic.)

This edition of the script asks for the reference in dialog box and then displays the result in a new TextEdit document, but the core routine could be adapted in any environment.


-- use a display dialog to ask for valid verse reference

set dd to display dialog "Enter a valid verse reference:" default answer "John 1:1"

set theReference to text returned of dd

multiModuleVerseLookup(theReference, true)

 

on multiModuleVerseLookup(theReference, quoteAsCitation)

-- set the delimiter between versions

set theDelimiter to return & "----------" & return

 

-- get moduleList

tell application "Accordance" to set moduleList to «event AccdVerL»

 

-- prepare textResult

set textResult to theReference & theDelimiter

 

repeat with thisModule in moduleList

-- lookup theReference in each module

tell application "Accordance" to set thisResult to «event AccdTxRf» {thisModule, theReference, quoteAsCitation}

 

-- add the result if the module contains theReference

if thisResult does not start with "ERR-" then set textResult to textResult & thisModule & return & thisResult & theDelimiter

end repeat

 

-- add display the result in a new TextEdit document

tell application "TextEdit"

activate

set textDoc to make new document at the front

set the text of textDoc to textResult

end tell

end multiModuleVerseLookup

 

 

A longer description of the script can be found here on my blog.

 

And, FWIW, I still think it'd be a good idea to have a sub-forum for scripting/automation/Services/siri lookup/etc. 

Link to comment
Share on other sites

@Joe - Thank you. Bummer for us windoze folks

 

@D - brilliant signature. Thank you. I'm thrilled that I figured out the Latin from memory (high school is a distant memory). For the Greek I had to confer with Prof Google. Hopefully one day in the not too distant future I'll learn Greek. Hebrew scares me, maybe I'm too old to learn that one. But I'm becoming fascinated with ancient history. The 3rd line stumped the Professor (Latvian?). Big Narnia fan here :) The links look very helpful! Thank you.

 

Cheers!

Edited by Drewster
Link to comment
Share on other sites

@D - brilliant signature. Thank you. I'm thrilled that I figured out the Latin from memory (high school is a distant memory). For the Greek I had to confer with Prof Google. Hopefully one day in the not too distant future I'll learn Greek. Hebrew scares me, maybe I'm too old to learn that one. But I'm becoming fascinated with ancient history. The 3rd line stumped the Professor (Latvian?). Big Narnia fan here :) The links look very helpful! Thank you.

 

Cheers!

 

The third line is an Akkadian translation of the same."lišanu ēdēnitu damqitu lišanu mītu" but alas I can no longer read it myself. Akkadian morphology is a lot of fun, if you like intricate morphology. I found it was helpful with Hebrew morph in a sort of a way. I don't know if anyone is too old to learn something of a thing if they want to. I found my eyes are not so good at discerning the nikkud at regular font sizes but Accordance can increase the size so that's a big plus.

 

Thx

D

Edited by דָנִיאֶל
Link to comment
Share on other sites

  • 7 months later...

Hi @Joe Weaks,

 

When we use this AppleScript to get verses and set CopyAsCitation to "true", does it get the text-style set in Accordance?

I'm not able to get the text to be as the same as I would get from the "Get Verses" service. It seems the text got from the AppleScript does not have any style (plaintext).

Link to comment
Share on other sites

Hi @Joe Weaks,

 

When we use this AppleScript to get verses and set CopyAsCitation to "true", does it get the text-style set in Accordance?

I'm not able to get the text to be as the same as I would get from the "Get Verses" service. It seems the text got from the AppleScript does not have any style (plaintext).

 

Hi, Martin,

 

You can adjust the format of the script, using the "Citation" panel of Accordance preferences, but unfortunately it loses style information in the scripting process such as bold and color, etc.

 

To copy such style info, you have to use the clipboard. The Text Browser gives you quick access to these versions to copy from.

Link to comment
Share on other sites

Hi, Martin,

 

You can adjust the format of the script, using the "Citation" panel of Accordance preferences, but unfortunately it loses style information in the scripting process such as bold and color, etc.

 

To copy such style info, you have to use the clipboard. The Text Browser gives you quick access to these versions to copy from.

Ok. Thanks!

I was making a Keyboard Maestro macro to get Hebrew texts. It allows me to remove the cantillation marks or "vowels and cantillation marks". Having to change the Hebrew export options is not a pleasant experience. I was hoping Accordance can add these options to the "Copy As" contextual menu. But for now, I'll do the job myself.

 

I was hoping that the style information could be preserved, so that I could add one more option: "Use Accordance Style". It's ok I can't have it.

LoTYPyA.png

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