On May 9, 2012, at 5:18PM, Axel Luttgens wrote:
Hello Daniel,
Please don't feel guilty. :-)
The first proposals, as of Shane or Michelle, were perfectly suitable.
Unless... unless your service needs to perform the test (is the third word a valid number?) many, many times per second and consume most of the service's computing duty, in which case optimizations such as the ones suggested by Nigel and Emmanuel may of course prove extremely useful.
Now, it seems that I didn't receive a lot of messages those days [1], so that I possibly missed the gist of your problem...
Here's my preliminary script
to switchText of currentText from SearchString to ReplaceString
set storedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to SearchString
set currentText to currentText's text items
set AppleScript's text item delimiters to ReplaceString
set currentText to currentText as Unicode text
set AppleScript's text item delimiters to storedDelimiters
currentText
end switchText
on process()
tell application "System Events"
keystroke "c" using command down --copy. whatever app the user is using, this should work
quit
end tell
get the clipboard as text
set _selection to result
Here's where I'm stumped for now... _selection could contain the number in the first word (e.g. 3 John) or the second word (e.g. Luke 15) or the third word (e.g. II Kings 15:11)
if _selection contains (number) then -- did the user select a reference to look up or a word to search for? If it has a number present then it is a reference
(* if the selected text begins with the letter 'I' and includes a number in the string, then it is a reference to a book of the Bible such as 1, 2 or third john (not Isaiah). Change it to a '1', '2' or '3' *)
-- here I used Nigel Garvey's script to get this number based on the number 36
if word 1 of _selection is "I" and (word 3 of _selection is in "3635343323130292827262524222120191817161514110") then
set newRef to switchText of (word 1 of _selection) from "I" to "1"
set the clipboard to newRef
else if word 1 of _selection is "II" and (word 3 of _selection is in "3635343323130292827262524222120191817161514110") then
set newRef to switchText of (word 1 of _selection) from "II" to "2"
set the clipboard to newRef
else if word 1 of _selection is "III" and (word 3 of _selection is in "3635343323130292827262524222120191817161514110") then
set newRef to switchText of (word 1 of _selection) from "III" to "3"
set the clipboard to newRef
else
set the clipboard to _selection
end if
tell application "SomeApplication" to activate
<blah blah>
else
set the clipboard to _selection
tell application "SomeApplication" to activate
<blah blah>
-Daniel