Adding a link to a text via applescript

Hello,

I’m working in Devonthink pro, along with a Bible study program based on Sword (macsword.com). I’d like to create a little script that would do the following :
Turn the selected scripture reference into a Sword link.
eg. “Exodus 2:3” must link to “sword://FreLSG/Exodus 2:3”

I have tried creating this script with automator, and with script editor, without success. I am fairly new to applescript.

An evolution of this script would take each scripture in a selected text or a document (search based on a regular expression) and turn it into a sword link.

So if you are interested in helping me, or if there is a similar existing script I can modify, plesa let me know !!!

I’m not familiar with MacSword. Is it verse and commentary or just verse?

Edit: What I mean is, would it be possible just to import a text version of the Bible and use AppleScript to change document names or aliases to “Exodus 2:3” or whatever?

I realize that’s not the ideal functionality, but it might be an alternative. I don’t understand why this isn’t working for you, but I try to keep everything in DTP so I never make real links.

Try experimenting with drag and drop form MacSword to DT. I’ve done a little of that and depending on my selection in MacSword it seems to work.

A simple script to add a URL looks like this (assuming a rich text document is visible in the frontmost window):


tell application "DEVONthink Pro"
	try
		set theWindow to think window 1
		tell selected text of theWindow to set URL to "http://www.apple.com"
		tell theWindow to save
	end try
end tell

Apologies for jumping in here, but maybe this is useful. I think Christian has given you good advice on using the URL property of the selected text (applescript inheritance can be cool), but that devonthink can’t quite do what you want (correct me Christian if I am wrong)…

I think what you want is something like this


tell application "DEVONthink Pro"
	try
		set url_stub to "sword://FreLSG/"
		
		set theWindow to think window 1
		tell selected text of theWindow to set URL to url_stub & (selected text of theWindow)
		
		
		tell theWindow to save
	end try
end tell

That will indeed embed the kind of URL you want. Hover over the link and you will see what sword://FreLSG/Exodus%2010:23 But the problem is that devonthink won’t jump to a macsword link because the program doesn’t pass those links to the os in the way you want it to.

In other words, run the same code block, but change the third line to

set url_stub to "mailto://"

then highlight a mail address. That link will work on it when you double click it, but devonthink doesn’t recognize the sword:// link as something the system can handle (or at least my dtpro doesn’t, but my safari will.)

does that make sense…?
erico

It’s a known issue, this will be fixed by the next release.

Thank you very much for your help. Links to Macsword don’t work on my system either.

Now I’m looking forward to the next release, if that means that this bug is fixed.