Jump to content


Photo

Display Scripture with Launchbar


  • Please log in to reply
1 reply to this topic

#1 ChristianB

ChristianB

    Bronze

  • Active Members
  • PipPip
  • 69 posts
  • Gender:Male
  • Accordance Version:10.x

Posted 17 January 2009 - 09:12 AM

Here is an applescript which together with LaunchBar helps to look up scriptures very quick. It is an adaption of the applescripts by Joe Weaks made for Quicksilver.

-- Accordance Quicksilver Plugin
-- Version 0.2
-- QS plugin that handles text and interacts with Accordance engine
-- CC   Joseph Weaks, 2006
-- Creative Commons Attribution-NonCommercial-ShareAlike 2.5 license (http://creativecommons.org/licenses/by-nc-sa/2.5/)

-- adapted to make it work with Launchbar by Christian Bender, 2008 http://twitter.com/ptujec 
-- additional scripting to fix large type issues by :kelko: kelko < at > anakrino <.> de http://kelko.anakrino.de

---------------------------------------
-- Begin User Settings  --
---------------------------------------
-- You have three properties to set. Where to send the output, which module to use, and how to format the results if not displaying it in Accordance.

-- Indicate what to do with the resulting text.
property sendOutputTo : "LBDisplay"
-- "pasteInFrontApp" = pastes scripture text in front app
-- "LBDisplay" = displays scripture text in Quicksilver display
-- "LBReturn" = returns scripture text to Quicksilver ready for another action
-- "Accordance" = displays the result in a new Accordance window of type specified in theModule


-- Set theModule, specifying which text to pull out of Accordance (3, "NRSV", etc.) or which type of window to display in Accordance ("Map", "English Tool", etc.). Read below for all options.
property theModule : "ELBER"
-- These first 2 options only good for passing results to another app (ie. can't show in Accordance)
-- 1 -- setting to an integer will pull the corresponding scripture from the text list in Accordance
-- "NRSV" -- setting to a scripture module short name will use that module

-- (These remaining options for theModule only work for sending result to Accordance)
-- "Verses"  -- displays verses in a new Accordance text window
-- "Words" -- displays words in a new Accordance text window
-- "Current Window" -- displays text in the current window open in Accordance ("Recycles" the front window)
-- "Map" -- displays text in a new Accordance Map window
-- "Timeline" -- displays text in a new Accordance Timeline window
-- "General Tool" -- displays text in a new Accordance General Tool window
-- "English Tool" -- displays text in a new Accordance English Tool window
-- "Reference Tool" -- displays text in a new Accordance Reference tool window
-- "Parallel" -- displays text in a new Accordance Parallel window
-- "User Notes" -- displays text in a new Accordance User Notes window
-- "User Tool" -- displays text in a new Accordance User Tool window
-- "Search All" -- displays text in a new Accordance Search All window


--Note:  Displaying the results in Accordance allows access to the first module of that type only, using the default settings for that type of module.  You may need to adjust the default search for "Field" if possible, such as for Parallel windows. Be savvy about sending a scripture reference to a Reference Tool, and a place name to a Map window, etc.


-- If not displaying in Accordance itself, determine how to format the results.
property quoteAs : "Citation"
-- "Citation"
-- "Paragraph" -- Doesn't handle citations in Hebrew well
-- "Verses"

---------------------------------------
-- End User Settings  --
---------------------------------------


---------------------------------------
-- The remainder of the script should only be tweaked if you know what you're doing.
---------------------------------------

on handle_string(theString)
	actionSorter(theString, theModule, quoteAs, sendOutputTo)
end handle_string

on actionSorter(theString, thisModule, thisFormat, outputDestination)
	
	if outputDestination begins with "Accordance" then
		showInAccordance(theString, thisModule)
	else
		-- Remove any non-alphanumeric characters from end of reference
		-- mostly for the purpose of removing a final carriage return
		set theString to removeExtraTrailingCharacters(theString)
		
		
		-- Looks up the module to use if a number is designated
		try
			set thisModule to thisModule as integer
			set thisModule to getModuleFromList(thisModule)
		end try
		
		if thisFormat begins with "Citation" then
			set quoteAsCitation to true
		else
			set quoteAsCitation to false
		end if
		
		-- Get the text from Accordance
		tell application "Accordance" to set theResult to «event AccdTxRf» {thisModule, theString, quoteAsCitation}
		
		
		if thisFormat begins with "Paragraph" then
			-- Reformats the text into paragraph format
			-- (It will have unsatisfactory results with texts of multiple books)
			set theResult to reformatScripture(theResult)
			
			-- Next line will add the full reference in a paragraph above the actual text
			--set theResult to theString & return & theResult
		end if
		
		set theResult to splitIntoLines(theResult)
		
		if outputDestination is "pasteInFrontApp" then
			pasteText(theResult)
			
		else if outputDestination is "LBDisplay" then
			tell application "LaunchBar" to display in large type theResult
		else if outputDestination is "LBReturn" then
			return theResult
		end if
	end if
	
end actionSorter

------------------------------------------------------------------------------
-- The rest of the script are supporting routines. 
-- Altering them requires more advanced knowledge.
------------------------------------------------------------------------------

on removeExtraTrailingCharacters(t)
	repeat
		if text -1 thru -1 of t is in "abcdefghijklmnopqrstuvwxyz1234567890" then exit repeat
		set t to text 1 thru -2 of t
	end repeat
	return t
end removeExtraTrailingCharacters


on getModuleFromList(m)
	tell application "Accordance" to set mList to «event AccdVerL»
	set m to (item m of mList)
	if (text 1 thru 1 of m) is not in "abcdefghijklmnopqrstuvwxyz1234567890" then set m to text 2 thru -1 of m -- strip preceding control character
end getModuleFromList


on pasteText(theString)
	tell application "System Events" to set FrontApp to (name of (processes whose frontmost is true)) as text
	tell application FrontApp
		set OldClipboard to the clipboard
		set the clipboard to {text:(theString as string), Unicode text:theString}
		tell application "System Events" to keystroke "v" using {command down}
		set the clipboard to OldClipboard
	end tell
end pasteText


on reformatScripture(t)
	set c to 0
	set u to ""
	
	repeat with p in (paragraphs in t)
		set o to offset of ":" in p
		set chap to text 1 thru (o - 1) of p
		set chap to last word of chap
		
		if chap > c then
			set c to chap
			set u to u & chap & ":"
		end if
		set u to u & (text (o + 1) thru -1 of p) & " "
	end repeat
	return u
end reformatScripture

on showInAccordance(t, thisModule)
	-- Possible thisModule parameters:
	-- ("Verses", "Words", "Current Window", "Map", "Timeline", "General Tool", "English Tool", "Reference Tool", "Parallel", "User Notes", "User Tool")
	
	tell application "Accordance"
		activate
		delay 0.4
		tell application "System Events"
			set accordProcess to the first process whose name begins with "Accord"
			tell accordProcess
				
				if thisModule is "Verses" then
					-- Remove any non-alphanumeric characters from end of reference
					-- mostly for the purpose of removing a final carriage return
					set t to removeExtraTrailingCharacters(t)
					
					keystroke "n" using {command down}
					delay 0.4
					keystroke "v" using {command down, option down, control down}
				else if thisModule is "Words" then
					keystroke "n" using {command down}
					delay 0.4
					keystroke "w" using {command down, option down, control down}
				else if thisModule is "Current Window" then
					-- these two tab strokes ensure the search box is hilighted
					keystroke tab using {shift down}
					delay 0.4
					keystroke tab
					
					-- keystroke "f" using {command down} -- Use this instead if its a Map or Timeline					
				else if thisModule is "Map" or thisModule is "Timeline" then
					click menu item thisModule of menu 1 of menu item "New" of menu 1 of menu bar item "File" of menu bar 1
					delay 0.4
					keystroke "f" using {command down}
				else
					click menu item thisModule of menu 1 of menu item "New" of menu 1 of menu bar item "File" of menu bar 1
				end if
				delay 0.4
				
				keystroke t
				delay 0.4
				
				keystroke return
				
				(* Can be used to copy results to the clipboard
				delay 0.4
				keystroke tab using {shift down}
				delay 0.4
				keystroke "a" using {command down}
				delay 0.4
				keystroke "c" using {command down}
				delay 0.4
				keystroke "h" using {command down}
				delay 0.4
				*)
			end tell
		end tell
	end tell
	
	(*  Can also be used if pasting results in previous app 
	set t to the cllipboard
	pasteText(t)
	*)
	
end showInAccordance

--------------------------------------------------
--
--	developed by:
--				 :kelko:
--				 kelko < at > anakrino <.> de
--				 http://kelko.anakrino.de
--
--
--------------------------------------------------

on splitIntoLines(inputText)
	
	set workString to inputText
	set tmp to "tmp"
	set maxCharactersPerLine to 90
	set maxCharacters to 0
	
	(*
		go through the whole text, 
		maybe more then one additional 
		new line is needed
	*)
	repeat
		set lfOffset to maxCharacters
		set idx to maxCharacters
		
		repeat
			set idx to (idx + 1)
			
			if idx > (length of workString) then
				exit repeat
			end if
			
			if character idx of workString is equal to return then
				set lfOffset to idx
				exit repeat
			end if
			
			if character idx of workString is equal to linefeed then
				set lfOffset to idx
				exit repeat
			end if
			
			
			if idx > maxCharacters + maxCharactersPerLine then
				exit repeat
			end if
			
		end repeat
		
		set maxCharacters to lfOffset + maxCharactersPerLine
		
		if (length of workString) > maxCharacters then
			
			set idx to maxCharacters
			
			repeat
				if character idx of workString is equal to space then
					set tmp to (get text 1 through (idx - 1) of workString) & linefeed & (get text (idx + 1) through (length of workString) of workString)
					set workString to tmp
					exit repeat
				end if
				
				if idx is equal to lfOffset then
					exit repeat
				end if
				
				set idx to (idx - 1)
				
			end repeat
			
		else
			exit repeat
		end if
		
	end repeat
	
	return workString
	
end splitIntoLines

Edited by ChristianB, 21 January 2009 - 09:06 AM.


#2 ChristianB

ChristianB

    Bronze

  • Active Members
  • PipPip
  • 69 posts
  • Gender:Male
  • Accordance Version:10.x

Posted 21 January 2009 - 05:52 AM

I added some Code to the Display Script which Joseph Weaks send me. (Thanks!)
The additional code changes German booknames into English so that Accordance understands them.

-- Accordance Quicksilver Plugin
-- Version 0.2
-- QS plugin that handles text and interacts with Accordance engine
-- CC   Joseph Weaks, 2006
-- Creative Commons Attribution-NonCommercial-ShareAlike 2.5 license (http://creativecommons.org/licenses/by-nc-sa/2.5/)

-- adapted to make it work with Launchbar by Christian Bender, 2008 http://twitter.com/ptujec 
-- additional scripting to fix large type issues by :kelko: kelko < at > anakrino <.> de http://kelko.anakrino.de
-- additional scripting to fix issues with German Booknames by Joseph Weaks, 2009

---------------------------------------
-- Begin User Settings  --
---------------------------------------
-- You have three properties to set. Where to send the output, which module to use, and how to format the results if not displaying it in Accordance.

-- Indicate what to do with the resulting text.
property sendOutputTo : "LBDisplay"
-- "pasteInFrontApp" = pastes scripture text in front app
-- "LBDisplay" = displays scripture text in Quicksilver display
-- "LBReturn" = returns scripture text to Quicksilver ready for another action
-- "Accordance" = displays the result in a new Accordance window of type specified in theModule


-- Set theModule, specifying which text to pull out of Accordance (3, "NRSV", etc.) or which type of window to display in Accordance ("Map", "English Tool", etc.). Read below for all options.
property theModule : "ELBER"
-- These first 2 options only good for passing results to another app (ie. can't show in Accordance)
-- 1 -- setting to an integer will pull the corresponding scripture from the text list in Accordance
-- "NRSV" -- setting to a scripture module short name will use that module

-- (These remaining options for theModule only work for sending result to Accordance)
-- "Verses"  -- displays verses in a new Accordance text window
-- "Words" -- displays words in a new Accordance text window
-- "Current Window" -- displays text in the current window open in Accordance ("Recycles" the front window)
-- "Map" -- displays text in a new Accordance Map window
-- "Timeline" -- displays text in a new Accordance Timeline window
-- "General Tool" -- displays text in a new Accordance General Tool window
-- "English Tool" -- displays text in a new Accordance English Tool window
-- "Reference Tool" -- displays text in a new Accordance Reference tool window
-- "Parallel" -- displays text in a new Accordance Parallel window
-- "User Notes" -- displays text in a new Accordance User Notes window
-- "User Tool" -- displays text in a new Accordance User Tool window
-- "Search All" -- displays text in a new Accordance Search All window


--Note:  Displaying the results in Accordance allows access to the first module of that type only, using the default settings for that type of module.  You may need to adjust the default search for "Field" if possible, such as for Parallel windows. Be savvy about sending a scripture reference to a Reference Tool, and a place name to a Map window, etc.


-- If not displaying in Accordance itself, determine how to format the results.
property quoteAs : "Citation"
-- "Citation"
-- "Paragraph" -- Doesn't handle citations in Hebrew well
-- "Verses"

---------------------------------------
-- End User Settings  --
---------------------------------------

-- Code to replace any German book title containing the book string with the corresponding English title in the same place.

property GermanBookString : "Genesis | Exodus | Levitikus | Numeri | Deuternomium | Josua | Richter | Rut | 1Könige | 2Könige | 1Chronik | 2Chronik | Esra | Nehemia | Ester | Hiob | Psalmen | Sprichwörter | Sprueche | Kohelet | Prediger | Hohelied | Jesaja | Jeremia | Klagelieder | Hesekiel | Hosea | Obadja | Jona | Micha | Habakuk | Zefanja | Haggai | Sacharja | Maleachi | Matthäus | Markus | Lukas | Johannes | Apostelgeschichte | Römer | 1Korinther | 2Korinther | Galater | Epheser | Philipper | Kolosser | 1Thessalonicher | 2Thessalonicher | 1Timotheus | 2Timotheus | Hebräer | Jakobus | 1Petrus | 2petrus | 1Johannes | 2Johannes | 3Johannes | Judas | Offenbarung"


property GermanBookList : {"Genesis", "Exodus", "Levitikus", "Numeri", "Deuternomium", "Josua", "Richter", "Rut", "1Könige", "2Könige", "1Chronik", "2Chronik", "Esra", "Nehemia", "Ester", "Hiob", "Psalmen", "Sprichwörter", "Sprueche", "Kohelet", "Prediger", "Hohelied", "Jesaja", "Jeremia", "Klagelieder", "Hesekiel", "Hosea", "Obadja", "Jona", "Micha", "Habakuk", "Zefanja", "Haggai", "Sacharja", "Maleachi", "Matthäus", "Markus", "Lukas", "Johannes", "Apostelgeschichte", "Römer", "1Korinther", "2Korinther", "Galater", "Epheser", "Philipper", "Kolosser", "1Thessalonicher", "2Thessalonicher", "1Timotheus", "2Timotheus", "Hebräer", "Jakobus", "1Petrus", "2Petrus", "1Johannes", "2Johannes", "3Johannes", "Judas", "Offenbarung"}

---------------------------------------
-- The remainder of the script should only be tweaked if you know what you're doing.
---------------------------------------

on handle_string(theString)
	actionSorter(theString, theModule, quoteAs, sendOutputTo)
end handle_string

on actionSorter(theString, thisModule, thisFormat, outputDestination)
	
	if outputDestination begins with "Accordance" then
		showInAccordance(theString, thisModule)
	else
		-- Remove any non-alphanumeric characters from end of reference
		-- mostly for the purpose of removing a final carriage return
		set theString to removeExtraTrailingCharacters(theString)
		
		
		-- Looks up the module to use if a number is designated
		try
			set thisModule to thisModule as integer
			set thisModule to getModuleFromList(thisModule)
		end try
		
		if thisFormat begins with "Citation" then
			set quoteAsCitation to true
		else
			set quoteAsCitation to false
		end if
		
		-- replace book title 
		set theString to convertGermanTitle2English(theString)
		
		
		-- Get the text from Accordance
		tell application "Accordance" to set theResult to «event AccdTxRf» {thisModule, theString, quoteAsCitation}
		
		
		if thisFormat begins with "Paragraph" then
			-- Reformats the text into paragraph format
			-- (It will have unsatisfactory results with texts of multiple books)
			set theResult to reformatScripture(theResult)
			
			-- Next line will add the full reference in a paragraph above the actual text
			--set theResult to theString & return & theResult
		end if
		
		set theResult to splitIntoLines(theResult)
		
		if outputDestination is "pasteInFrontApp" then
			pasteText(theResult)
			
		else if outputDestination is "LBDisplay" then
			tell application "LaunchBar" to display in large type theResult
		else if outputDestination is "LBReturn" then
			return theResult
		end if
	end if
	
end actionSorter

------------------------------------------------------------------------------
-- The rest of the script are supporting routines. 
-- Altering them requires more advanced knowledge.
------------------------------------------------------------------------------

on removeExtraTrailingCharacters(t)
	repeat
		if text -1 thru -1 of t is in "abcdefghijklmnopqrstuvwxyz1234567890" then exit repeat
		set t to text 1 thru -2 of t
	end repeat
	return t
end removeExtraTrailingCharacters


on getModuleFromList(m)
	tell application "Accordance" to set mList to «event AccdVerL»
	set m to (item m of mList)
	if (text 1 thru 1 of m) is not in "abcdefghijklmnopqrstuvwxyz1234567890" then set m to text 2 thru -1 of m -- strip preceding control character
end getModuleFromList


on pasteText(theString)
	tell application "System Events" to set FrontApp to (name of (processes whose frontmost is true)) as text
	tell application FrontApp
		set OldClipboard to the clipboard
		set the clipboard to {text:(theString as string), Unicode text:theString}
		tell application "System Events" to keystroke "v" using {command down}
		set the clipboard to OldClipboard
	end tell
end pasteText


on reformatScripture(t)
	set c to 0
	set u to ""
	
	repeat with p in (paragraphs in t)
		set o to offset of ":" in p
		set chap to text 1 thru (o - 1) of p
		set chap to last word of chap
		
		if chap > c then
			set c to chap
			set u to u & chap & ":"
		end if
		set u to u & (text (o + 1) thru -1 of p) & " "
	end repeat
	return u
end reformatScripture

on showInAccordance(t, thisModule)
	-- Possible thisModule parameters:
	-- ("Verses", "Words", "Current Window", "Map", "Timeline", "General Tool", "English Tool", "Reference Tool", "Parallel", "User Notes", "User Tool")
	
	tell application "Accordance"
		activate
		delay 0.4
		tell application "System Events"
			set accordProcess to the first process whose name begins with "Accord"
			tell accordProcess
				
				if thisModule is "Verses" then
					-- Remove any non-alphanumeric characters from end of reference
					-- mostly for the purpose of removing a final carriage return
					set t to removeExtraTrailingCharacters(t)
					
					keystroke "n" using {command down}
					delay 0.4
					keystroke "v" using {command down, option down, control down}
				else if thisModule is "Words" then
					keystroke "n" using {command down}
					delay 0.4
					keystroke "w" using {command down, option down, control down}
				else if thisModule is "Current Window" then
					-- these two tab strokes ensure the search box is hilighted
					keystroke tab using {shift down}
					delay 0.4
					keystroke tab
					
					-- keystroke "f" using {command down} -- Use this instead if its a Map or Timeline					
				else if thisModule is "Map" or thisModule is "Timeline" then
					click menu item thisModule of menu 1 of menu item "New" of menu 1 of menu bar item "File" of menu bar 1
					delay 0.4
					keystroke "f" using {command down}
				else
					click menu item thisModule of menu 1 of menu item "New" of menu 1 of menu bar item "File" of menu bar 1
				end if
				delay 0.4
				
				keystroke t
				delay 0.4
				
				keystroke return
				
				(* Can be used to copy results to the clipboard
				delay 0.4
				keystroke tab using {shift down}
				delay 0.4
				keystroke "a" using {command down}
				delay 0.4
				keystroke "c" using {command down}
				delay 0.4
				keystroke "h" using {command down}
				delay 0.4
				*)
			end tell
		end tell
	end tell
	
	(*  Can also be used if pasting results in previous app 
	set t to the cllipboard
	pasteText(t)
	*)
	
end showInAccordance

--------------------------------------------------
--
--	developed by:
--				 :kelko:
--				 kelko < at > anakrino <.> de
--				 http://kelko.anakrino.de
--
--
--------------------------------------------------

on splitIntoLines(inputText)
	
	set workString to inputText
	set tmp to "tmp"
	set maxCharactersPerLine to 90
	set maxCharacters to 0
	
	(*
		go through the whole text, 
		maybe more then one additional 
		new line is needed
	*)
	repeat
		set lfOffset to maxCharacters
		set idx to maxCharacters
		
		repeat
			set idx to (idx + 1)
			
			if idx > (length of workString) then
				exit repeat
			end if
			
			if character idx of workString is equal to return then
				set lfOffset to idx
				exit repeat
			end if
			
			if character idx of workString is equal to linefeed then
				set lfOffset to idx
				exit repeat
			end if
			
			
			if idx > maxCharacters + maxCharactersPerLine then
				exit repeat
			end if
			
		end repeat
		
		set maxCharacters to lfOffset + maxCharactersPerLine
		
		if (length of workString) > maxCharacters then
			
			set idx to maxCharacters
			
			repeat
				if character idx of workString is equal to space then
					set tmp to (get text 1 through (idx - 1) of workString) & linefeed & (get text (idx + 1) through (length of workString) of workString)
					set workString to tmp
					exit repeat
				end if
				
				if idx is equal to lfOffset then
					exit repeat
				end if
				
				set idx to (idx - 1)
				
			end repeat
			
		else
			exit repeat
		end if
		
	end repeat
	
	return workString
	
end splitIntoLines

---------------------------------------
-- Routine to replace any German book title containing the book string with the corresponding English title in the same place.
---------------------------------------

on convertGermanTitle2English(t)
	set o to offset of " " in t
	set bookName to text 1 thru (o - 1) of t
	if bookName is in GermanBookString then
		repeat with n from 1 to (length of GermanBookList)
			if (get item n of GermanBookList) starts with bookName then
				-- replace any German book title containing the book string with the corresponding English title in the same place.
				set bookName to item n of EnglishBookList
			end if
		end repeat
	end if
	return (bookName & text o thru -1 of t)
end convertGermanTitle2English

Edited by Ptujec, 21 January 2009 - 08:55 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users