Jump to content


Photo

Script for Multi-version Verse Lookup

script applescript

  • Please log in to reply
21 replies to this topic

#1 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,381 posts
  • Gender:Male
  • Location:Odessa, TX
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:11.x

Posted 20 October 2018 - 06:41 PM

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, 21 October 2018 - 05:25 PM.

  • Martin Zhang and Ιακοβ like this
Joe Weaks
The Macintosh Biblioblog

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

#2 OSchrock

OSchrock

    Gold

  • Active Members
  • PipPipPipPip
  • 214 posts
  • Gender:Male
  • Location:USA / Brazil
  • Accordance Version:13.x
  • Platforms:Mac OS X, iOS

Posted 20 October 2018 - 09:19 PM

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


  • Ιακοβ likes this

#3 Ιακοβ

Ιακοβ

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 678 posts
  • Gender:Male
  • Location:Australia
  • Interests:Studying MDiv. Greek. Hebrew.
  • Accordance Version:11.x
  • Platforms:Mac OS X, iOS

Posted 21 October 2018 - 05:47 AM

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.

 

Attached File  Screen Shot 2018-10-21 at 9.58.57 pm.png   230.13KB   1 downloads

 

So for example, all LXX posts:

 

https://www.accordan...ags/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 Ιακοβ, 21 October 2018 - 05:53 AM.

  • Joe Weaks likes this
My top 5 feature requests:
  1. 15pt font size for reading text (bible, journal articles, commentaries, etc...)
  2. Improved searching for Journal articles. (So we can search for journal article by verse + english text)
  3. Display Journal titles in journal search results. (Imagine a google search where you saw the page text but no headings?)
  4. Improved greek text search—i.e. allow searching of all greek text the same way you would search LXX+NT, i.e. LXX+NT+ApocFathers+etc...
  5. Phrase (sympathetic) highlighting.

#4 OSchrock

OSchrock

    Gold

  • Active Members
  • PipPipPipPip
  • 214 posts
  • Gender:Male
  • Location:USA / Brazil
  • Accordance Version:13.x
  • Platforms:Mac OS X, iOS

Posted 22 October 2018 - 08:58 AM

 

-- 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, 22 October 2018 - 08:59 AM.

  • Joe Weaks likes this

#5 Graham Buck

Graham Buck

    Platinum

  • Accordance
  • 617 posts
  • Gender:Male
  • Location:God's Country (New England)
  • Accordance Version:12.x
  • Platforms:Mac OS X, iOS

Posted 22 October 2018 - 09:10 AM

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

Attached Files


  • Joe Weaks and OSchrock like this

Graham Buck

 

iOS Developer
OakTree Software


#6 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,381 posts
  • Gender:Male
  • Location:Odessa, TX
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:11.x

Posted 22 October 2018 - 08:25 PM

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)

Joe Weaks
The Macintosh Biblioblog

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

#7 [email protected]

[email protected]

    Member

  • Active Members
  • Pip
  • 11 posts

Posted 24 October 2018 - 07:20 PM

These are fantastic! 



#8 [email protected]

[email protected]

    Member

  • Active Members
  • Pip
  • 11 posts

Posted 24 October 2018 - 07:43 PM

 

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?



#9 [email protected]

[email protected]

    Member

  • Active Members
  • Pip
  • 11 posts

Posted 24 October 2018 - 07:55 PM

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"}


#10 Graham Buck

Graham Buck

    Platinum

  • Accordance
  • 617 posts
  • Gender:Male
  • Location:God's Country (New England)
  • Accordance Version:12.x
  • Platforms:Mac OS X, iOS

Posted 24 October 2018 - 08:37 PM

 

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.

 

Attached File  Screen Shot 2018-10-24 at 9.29.47 PM.png   624.66KB   1 downloads

Attached File  Screen Shot 2018-10-24 at 9.31.08 PM.png   666.91KB   0 downloads

Attached File  Screen Shot 2018-10-24 at 9.31.28 PM.png   711.77KB   0 downloads

 

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"}


Graham Buck

 

iOS Developer
OakTree Software


#11 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,381 posts
  • Gender:Male
  • Location:Odessa, TX
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:11.x

Posted 24 October 2018 - 08:48 PM

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

Joe Weaks
The Macintosh Biblioblog

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

#12 [email protected]

[email protected]

    Member

  • Active Members
  • Pip
  • 11 posts

Posted 28 October 2018 - 11:49 PM

 

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!



#13 Martin Zhang

Martin Zhang

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 517 posts
  • Gender:Male
  • Accordance Version:13.x
  • Platforms:Mac OS X, Windows, iOS, Android

Posted 18 June 2020 - 07:55 AM

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"}

 


Martin
Accordance tutorials in Chinese.


#14 Martin Zhang

Martin Zhang

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 517 posts
  • Gender:Male
  • Accordance Version:13.x
  • Platforms:Mac OS X, Windows, iOS, Android

Posted 18 June 2020 - 08:12 AM

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. 

 


Martin
Accordance tutorials in Chinese.


#15 mgvh

mgvh

    Gold

  • Active Members
  • PipPipPipPip
  • 426 posts
  • Gender:Male
  • Location:Maryland, USA
  • Interests:Archaeology, Photography, Biking
  • Accordance Version:13.x
  • Platforms:Windows, Android

Posted 18 June 2020 - 08:43 AM

I'm assuming this is a Mac thing!

Is there a comparable Windows thing?


  • Drewster likes this

#16 Drewster

Drewster

    Silver

  • Active Members
  • PipPipPip
  • 113 posts
  • Gender:Male
  • Interests:Football (ie, soccer). Bible. Small groups. Missions. Relationships. Counseling. Flying.
  • Accordance Version:13.x
  • Platforms:Windows, iOS, Android

Posted 18 June 2020 - 11:15 AM

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



#17 דָנִיאֶל

דָנִיאֶל

    Ruby

  • Super Member
  • PipPipPipPipPipPipPip
  • 6,026 posts
  • Gender:Male
  • Accordance Version:12.x
  • Platforms:Mac OS X, Windows, Android

Posted 18 June 2020 - 11:24 AM

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


Sola lingua bona est lingua mortua
ἡ μόνη ἀγαθὴ γλῶσσα γλῶσσα νεκρὰ ἐστιν
lišanu ēdēnitu damqitu lišanu mītu

"Du stammst vom Herrn Adam und der Herrin Eva ab", sagte Aslan. "Und das ist zugleich Ehre genug, um das Häupt des ärmsten Bettlers zu erheben, und genug, um die Schultern des größten Kaisers auf Erden zu beugen. Sei zufrieden." Aslan, Die Chroniken von Narnia, Prinz Kaspian von Narnia. CS Lewis. Übersetzt von Wolfgang Holbein und Christian Rendel.

Accordance Syntax Search For Wallace's Greek Grammar Beyond the Basics : https://github.com/4...WallaceInSyntax

Accordance Crib Sheets: http://47rooks.com/l...ch-crib-sheets/


Accordance Configurations :

Mac : 2009 27" iMac
12GB RAM

Windows : MSI GE72 7RE Apache Pro laptop
Intel Core Duo Intel i7 Kabylake

Android : Samsung Note III 5.0, Samsung Tab S3 7.0 and Lenovo TAB4 8" 7.1

#18 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,381 posts
  • Gender:Male
  • Location:Odessa, TX
  • Interests:I like things that are Orange, and possibly Blue.
  • Accordance Version:11.x

Posted 18 June 2020 - 03:19 PM

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


Joe Weaks
The Macintosh Biblioblog

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

#19 Martin Zhang

Martin Zhang

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 517 posts
  • Gender:Male
  • Accordance Version:13.x
  • Platforms:Mac OS X, Windows, iOS, Android

Posted 18 June 2020 - 03:38 PM

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.

Attached File  Screenshot 2020-06-18 16.35.26.png   356.83KB   0 downloads Attached File  Screenshot 2020-06-18 16.35.10.png   120.25KB   0 downloads

 

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. 

 


Martin
Accordance tutorials in Chinese.


#20 Martin Zhang

Martin Zhang

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 517 posts
  • Gender:Male
  • Accordance Version:13.x
  • Platforms:Mac OS X, Windows, iOS, Android

Posted 18 June 2020 - 07:42 PM

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. 


Martin
Accordance tutorials in Chinese.






Also tagged with one or more of these keywords: script, applescript

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users