I have a script which is triggered upon selection of an item. This script opens the URL of the item in a separate window. Its for use with RSS feeds where I don’t want to mess with the feed item and want to go straight to the full article on the referenced web site.
The problem is that, as far as I can tell, this script needs to be attached to the item for it to be triggered. That means that, upon selecting the RSS feed group, I need to select all items and attach the script manually. What I would like to do is write a script which, upon selection of the feed group, automatically attaches the relevant script above to all of the child items. Unfortunately, I can’t find a command to do this. Any suggestions?
This will attach the same script to all items in a selection (assumes they are in the same group)
tell application id "com.devon-technologies.thinkpro2"
set theGroup to the current group
set theScript to attached script of theGroup
set theSelection to the selection
repeat with this_item in theSelection
set attached script of this_item to theScript
end repeat
end tell
This is an interesting situation. It seems (to me) that the feed isn’t actually treated as a group.
To start at the beginning, here’s my code based upon what Korm just posted:
tell application id "com.devon-technologies.thinkpro2"
set theGroup to the current group
set theScript to "/Users/me/Scripts/AutoViewRSS.scpt"
set theSelection to the selection
repeat with this_item in theSelection
set attached script of this_item to theScript
end repeat
end tell
The result was that the script was attached to the current feed, not the items within that feed. If I select all of the items in the feed and run this script, it works, of course. But what I’d like to do is run the script when the feed, itself, is selected.
I’ve tried a number of variations. For instance, this code attached the script to all of the feeds instead of all of the items within the selected feed:
tell application "DEVONthink Pro"
set theParent to current group
set theSelection to children of theParent
repeat with theChild in theSelection
set attached script of theChild to "/Users/me/Scripts/AutoViewRSS.scpt"
end repeat
end tell
The “current group” is recognized as the parent of the feed, not the feed, itself. The items within the RSS feed group don’t seem to be recognized in the same way that the items within a normal group are. Any suggestions on how I might access the items within the feed, itself?
-- Open selected record and browse to associated URL
-- Created by Tom Shannon
on triggered(theRecord)
try
tell application "DEVONthink Pro"
set theURL to URL of theRecord
if theURL is {} then error "Please select a record with an associted URL."
open tab for URL theURL
set zoomed of think window 1 to true
end tell
on error error_message number error_number
if the error_number is not -128 then
try
display alert "DEVONthink Pro" message error_message as warning
on error number error_number
if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
end try
end if
end try
end triggered
Thanks! One question: I can’t seem to stop it zooming to full screen. I took out the “set zoomed” line – didn’t affect it. I then tried setting it to “false.” Again, couldn’t stop it zooming. How can this be?
Good script. I was trying to figure out how to use the attached script for just this functionality. However I seem to be getting one small anomaly.
When I click on the record that has a URL, a new tab opens. But, the tab doesn’t contain anything and the title is the UUID of the linked record. Then the record that I actually want to see does open, but in a new window.
What I’d like to have happen is just to have the linked record open in a tab.