Jump to content


Photo

Script for Multi-version Verse Lookup

script applescript

  • Please log in to reply
11 replies to this topic

#1 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,327 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.

  • Ιακοβ likes this
Joe Weaks
The Macintosh Biblioblog

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

#2 OSchrock

OSchrock

    Silver

  • Active Members
  • PipPipPip
  • 118 posts
  • Gender:Male
  • Location:USA / Brazil
  • Accordance Version:12.x
  • Platforms:Mac OS X

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
  • 666 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

    Silver

  • Active Members
  • PipPipPip
  • 118 posts
  • Gender:Male
  • Location:USA / Brazil
  • Accordance Version:12.x
  • Platforms:Mac OS X

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

    Gold

  • Accordance
  • 313 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 Programmer
Content Development [Ninja]
OakTree Software


#6 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,327 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
  • 10 posts

Posted 24 October 2018 - 07:20 PM

These are fantastic! 



#8 [email protected]

[email protected]

    Member

  • Active Members
  • Pip
  • 10 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
  • 10 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

    Gold

  • Accordance
  • 313 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   0 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 Programmer
Content Development [Ninja]
OakTree Software


#11 Joe Weaks

Joe Weaks

    Platinum

  • Active Members
  • PipPipPipPipPip
  • 1,327 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
  • 10 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!







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