I am new to the very powerful scripting dictionary in DEVONthink.
(Many years ago at Apple, I worked on the original AppleScript implementation for Aperture, so I have a sense of how very impressive the AppleScript abilities of DT are. Thank you!)
What would be the recommended way to write a script that reveals a record in the main DT window?
I have found the open tab command and have tried:
open tab for record newRecord in window 1
which does not open a new window (which is what I want) but does not reveal the new record in the window.
Is there a better way to reveal a record in AppleScript?
I’m not sure if this is what you’re after, but the following AppleScript code would create a new record in the currently selected group and select the newly created record:
tell application id "DNtp"
set newRecord to create record with {type:markdown, content:"Some text content.", name:"A test record"} in current group
set selection of viewer window 1 to (newRecord as list)
end tell
Many thanks to YOU for all your work on the Cocoa frameworks, Aperture and the good & fun music!
Personally I consider Aperture as one of the best applications ever made by Apple and I’m still using it today (I try to keep my old Mac & camera hardware alive so I can keep using Aperture). Thank you!
This would only reveal one specific record. In this case, I want to reveal the global inbox after an import of an item, but more generally would like to reveal one specific record for other scripts.
Here is one simple approach to checking for a record by UUID then opening a tab in the current think window…
tell application id "DNtp"
set theRecord to get record with uuid "x-devonthink-item://B0776EE7-4EB3-4E0E-8595-57A140B45C9A"
--> content id 157088 of database id 5
if theRecord is not missing value then
set theTab to open tab for record theRecord in think window 1
--> tab id 51 of viewer window id 150
set current tab of think window 1 to theTab -- Sets the active tab
end if
end tell
However, if you are just wanting to show the Global Inbox, you don’t necessarily need a script. This could be done via a its database list, i.e., x-devonthink-item://inbox or even using a hotkey if it’s favorited in the Go > Favorites menu.
but more generally would like to reveal one specific record for other scripts.
Can you elaborate on this? Many scripts don’t need to have a document selected in order to run properly.
In this case, I am trying to write a service that imports a file selected in the Finder to DT and then moves the original file to the trash.
That is working fine.
Because I tend to be an over-cautious double-checker and am putting the original in the trash, I also want the script to show the inbox so that I can verify the import happened as expected.
If the script doesn’t do this, I know I will do it manually every time because it will bother me not to check.
So I want to have the inbox selected in the sidebar of the main window automatically without opening additional windows or tabs that I have to close manually.
In the general case, if I wrote a script that moved items to a particular group, for example, I would similarly want to end the script by having that group selected in the sidebar so I could verify that things happened as I intended.
I played with this but decided I’d prefer not to. (Manually clicking the Inbox in the sidebar doesn’t take that much longer than a hotkey in this case)
But now I have no favorites and an empty Favorites section header in the sidebar. Is there a way to remove it from the sidebar?
In this case, I am trying to write a service that imports a file selected in the Finder to DT and then moves the original file to the trash.
There are already folder actions for this purpose that could be modified, something I just mentioned on another thread.
If the script doesn’t do this, I know I will do it manually every time because it will bother me not to check.
Why don’t you just add a beep or a notification? They’re easily satisfied by a boolean and unless your sound or notifications are off, they provide as a nice, simple confirmation.
A simple example…
tell application "Finder" to set selectedFiles to (get selection as alias list)
tell application id "DNtp"
repeat with theFile in selectedFiles
try
import POSIX path of theFile to incoming group
beep
on error msg
log message msg
end try
end repeat
end tell
There’s no need to look at DEVONthink for a confirmation then. At the beginning, for sure but once it’s habitual, the only time you look is when you don’t see or hear the notification.
Is there a way to remove it from the sidebar?
No. But you can drag it to a different position in the sidebar, including the bottom.
Because I know myself and I know I will want to see the imported item in the inbox if I am automatically putting the original in the trash.
So, I know I will end up checking manually but would prefer to automate that as much as possible.
I will take a look. I do already have the import and move to trash working fine though, just not performing a scripted reveal in the sidebar. But it sounds as if that is not generally scriptable.
Thank you very much, I really appreciate your kind words.
I also have an old iMac running Aperture, but I don’t use it actively. I was hoping Photomator was going to be a good-enough Aperture substitute for me once it added support for libraries outside of Photos, but now that Apple has bought that company, I need to wait and see before depending on it for photo organization.