with a growing database, I often find myself browsing and clicking through just to get new inspiration. While the see also function is already excellent, what I am looking for is a similar experience to a box of index cards, where I can just pick a card and be surprised - or the “random article” link in wikipedia.
do you think it might pe possible to write a script that could switch the view to a random file in the database?
tell application "DEVONthink Pro"
set db to database 1
repeat
try
set dum to count parents of the db
set num to random number from 1 to dum
set mum to parent num of the db
set chum to count mum's children
set num to random number from 1 to chum
set kiddo to child num of mum
if kiddo's type is not group then exit repeat
end try
end repeat
set the record of window 1 to kiddo
end tell
Yeah, I thought I needed a bit more error checking. Try this:
tell application "DEVONthink Pro"
set db to database 1
repeat
try
set dum to count parents of the db
set num to random number from 1 to dum
set mum to parent num of the db
set chum to count mum's children
set num to random number from 1 to chum
set kiddo to child num of mum
if kiddo's type is not group then exit repeat
end try
end repeat
if not (exists (the 1st document window whose visible is true)) then
open window for record kiddo
else
set myWindow to the 1st document window whose visible is true
set myWindow's record to kiddo
end if
end tell
that did it - wow! It opens a random document in a new window, in my case, an old tax report which did not belong there and after another run, something more interesting, as in: “And now for something completely different”.
One day I’ll find out how to tweak the script in a way that the documents open in the current viewer window instead a new document - but again, I am happy that it works - you fixed it! thanks!
sorry to bother you again, but since I discovered the Oblique Strategies - Deck (wikipedia), I try to change the script above, but I can’t get it to work.
What I am trying to do, is change the random script above to consider only records from the selected group and display it in the window that is already active instead of opening a new one.
While the above script works great in opening any record from the database in the new window, a script for the random display of folder contents would be great for creative strategies. For example, writing a short story and having the computer pick a scenario…
But I got stuck. Dear script wizards, please help!
I’m currently recovering from a virus ( a head cold in summer!), but once I’ve finished my recovery, I’ll get onto it - it’s no trouble, I like a challenge.
good luck with your virus, and thanks for the help!
Meanwhile, I tried to change the script myself. I got only half of the way, but here it is:
tell application id "com.devon-technologies.thinkpro2"
set cgr to the current group
set chnum to count cgr's children
set randnum to random number from 1 to chnum
set RandomRecord to child randnum of cgr
open window for record RandomRecord
--how can I set the selection of the viewer window?
--here is what I tried so far
--set the root of viewer window 1 to RandomRecord
--set selection of viewer window 1 to record RandomRecord
end tell
This script opens a random record in the current group in a new window.
For some reason, however, I can’t get it to open the random record in the active viewer window. Is it possible to set the selection of the viewer window at all, and if so, how?
ok, another one. Just discovered that you can use “some” for the randomness , which shortens my first applescript experiment quite a bit. I have no idea what I am doing here, never coded a line in my life, however: As with DTPO 2.0.1, the active record of a viewer window can’t be set, or at least, not by me…
tell application id "com.devon-technologies.thinkpro2"
try
set RandomRecord to some child of the current group
if RandomRecord's type is not group then exit repeat
end try
--if not (exists (the 1st document window whose visible is true)) then
open window for record RandomRecord
--else
--set myWindow to the 1st document window whose visible is true
--set myWindow's record to RandomRecord
--end if
end tell
Heck, what are the magic words to have the random record appear in the active viewer window? I don’t know. Dear different time-zone-people: How do you do (“it”)?
In my experience, using “some” gets inferior results to generating a random number from the count of the result; you get the same number far too often.
As far as the viewer window problem goes, a viewer window is something like a Finder window - you can’t display documents in it. On the other hand, if your random record is a group, DTPO will display it in a document window, even though you can’t do anything with it, like double-clicking on icons etc. I wrote something that deals with that problem:
tell application id "com.devon-technologies.thinkpro2"
set cgr to the current group
set chnum to count cgr's children
set randnum to random number from 1 to chnum
set RandomRecord to child randnum of cgr
set itsKind to kind of RandomRecord
if itsKind contains "Group" then
set the root of viewer window 1 to RandomRecord
else
if exists (the 1st document window whose visible is true) then
set docWin to the 1st document window whose visible is true
set docWin's record to RandomRecord
else
open window for record RandomRecord
end if
end if
end tell