Im trying to build a script witch can open the url of en element in Safari.
tell application id "com.devon-technologies.thinkpro2"
try
set this_selection to the selection
if this_selection is {} then error "Please select some contents."
repeat with this_record in this_selection
set this_url to the URL of this_record
tell application "Safari"
open location this_url
activate
end tell
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
end try
end tell
So far I can run this and open a url of an selected article but my goal is to a the script as the script of an article so it shoud run automaticly when I click on the article.
Any idea?
Sorry for my english.
You’re almost there… I took your script and modified it to be run from the script menu or run as a script attached to the record. What you want to do is select the record you want to have auto open and select the script button in the info panel. Attach this script to the record and it will automatically run the triggered routine when you click on the record. If you run the script manually it will execute the triggered code for all selected records. Hope this helps…
on run
tell application id "com.devon-technologies.thinkpro2"
try
set this_selection to the selection
if this_selection is {} then error "Please select some contents."
repeat with this_record in this_selection
my triggered(this_record)
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
end try
end tell
end run
on triggered(this_record)
tell application id "com.devon-technologies.thinkpro2"
set this_url to the URL of this_record
if this_url is not equal to "" then
tell application "Safari"
open location this_url
activate
end tell
end if
end tell
end triggered
Also… Here is a fun twist… This version of the script, when run from the script menu, attaches itself to the selected records. Then when the record is clicked on it runs the triggered command to display the URL. I use this kind of routine all the time in my stuff…
on run
tell application id "com.devon-technologies.thinkpro2"
try
set this_selection to the selection
if this_selection is {} then error "Please select some contents."
repeat with this_record in this_selection
set oldDelimiters to AppleScript's text item delimiters
tell application "Finder"
set scriptPath to path to me as text
set AppleScript's text item delimiters to ":"
set myName to last text item of scriptPath
set scriptPath to text items 1 thru -2 of scriptPath as string
set AppleScript's text item delimiters to oldDelimiters
end tell
repeat with theRecord in this_selection
tell application id "com.devon-technologies.thinkpro2"
set attached script of theRecord to (file (scriptPath & ":" & myName) as alias)
end tell
end repeat
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
end try
end tell
end run
on triggered(this_record)
tell application id "com.devon-technologies.thinkpro2"
set this_url to the URL of this_record
if this_url is not equal to "" then
tell application "Safari"
open location this_url
activate
end tell
end if
end tell
end triggered
Chris