Joe Weaks Posted October 20, 2018 Share Posted October 20, 2018 (edited) 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 October 21, 2018 by Joe Weaks 2 Link to comment Share on other sites More sharing options...
OSchrock Posted October 21, 2018 Share Posted October 21, 2018 This is awesome! Thank you for working on it and posting it here! 1 Link to comment Share on other sites More sharing options...
Ιακοβ Posted October 21, 2018 Share Posted October 21, 2018 (edited) 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. 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 October 21, 2018 by Ιακοβ 1 Link to comment Share on other sites More sharing options...
OSchrock Posted October 22, 2018 Share Posted October 22, 2018 (edited) -- 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 October 22, 2018 by OSchrock 1 Link to comment Share on other sites More sharing options...
Graham Buck Posted October 22, 2018 Share Posted October 22, 2018 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 2 Link to comment Share on other sites More sharing options...
Joe Weaks Posted October 23, 2018 Author Share Posted October 23, 2018 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 More sharing options...
wayne@dubbo.org Posted October 25, 2018 Share Posted October 25, 2018 These are fantastic! Link to comment Share on other sites More sharing options...
wayne@dubbo.org Posted October 25, 2018 Share Posted October 25, 2018 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 More sharing options...
wayne@dubbo.org Posted October 25, 2018 Share Posted October 25, 2018 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 More sharing options...
Graham Buck Posted October 25, 2018 Share Posted October 25, 2018 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. 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 More sharing options...
Joe Weaks Posted October 25, 2018 Author Share Posted October 25, 2018 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 More sharing options...
wayne@dubbo.org Posted October 29, 2018 Share Posted October 29, 2018 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 More sharing options...
Martin Z Posted June 18, 2020 Share Posted June 18, 2020 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. Screen Shot 2018-10-24 at 9.29.47 PM.png Screen Shot 2018-10-24 at 9.31.08 PM.png Screen 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 More sharing options...
Martin Z Posted June 18, 2020 Share Posted June 18, 2020 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 More sharing options...
mgvh Posted June 18, 2020 Share Posted June 18, 2020 I'm assuming this is a Mac thing! Is there a comparable Windows thing? 1 Link to comment Share on other sites More sharing options...
Drewster Posted June 18, 2020 Share Posted June 18, 2020 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 More sharing options...
Λύχνις Δαν Posted June 18, 2020 Share Posted June 18, 2020 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 More sharing options...
Joe Weaks Posted June 18, 2020 Author Share Posted June 18, 2020 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 More sharing options...
Martin Z Posted June 18, 2020 Share Posted June 18, 2020 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. 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 More sharing options...
Martin Z Posted June 19, 2020 Share Posted June 19, 2020 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 More sharing options...
Drewster Posted June 19, 2020 Share Posted June 19, 2020 (edited) @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 June 19, 2020 by Drewster Link to comment Share on other sites More sharing options...
Λύχνις Δαν Posted June 19, 2020 Share Posted June 19, 2020 (edited) @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 June 19, 2020 by דָנִיאֶל Link to comment Share on other sites More sharing options...
Martin Z Posted February 12, 2021 Share Posted February 12, 2021 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 More sharing options...
Joe Weaks Posted February 12, 2021 Author Share Posted February 12, 2021 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 More sharing options...
Martin Z Posted February 12, 2021 Share Posted February 12, 2021 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now