INBOX Watch folder - how to create various watch folders?

Apologies if this topic has been covered before - if so please redirect me to the answer…

I want to create various watch folders which will then move documents to different databases or groups (folders) within DTPro. My plan is to use Hazel to automate the workflow…

I currently use the INBOX watch folder that comes with DTPro, I have also looked at the Applescripts such as “DEVONthink - Import & Delete”, but these just move files to the main INBOX. [I am aware of other scripts that gives a dialog to chose the folder, but I want to preset this]

Is there a way to modify the script to set the destination path to a precise group/folder within DTPro (I have no applescript experience). If this is possible, I could then create different scripts for each of my watch folders

The script is below - can I change this to set the destination path & then save as a new applescript…

– DEVONthink - Import & Delete.applescript
– Created by Christian Grunenberg on Fri Mar 26 2010.
– Copyright © 2010-2014. All rights reserved.

on adding folder items to this_folder after receiving added_items
try
if (count of added_items) is greater than 0 then
tell application id “DNtp” to launch
repeat with theItem in added_items
try
set thePath to theItem as text
if thePath does not end with “.download:” and thePath does not end with “.crdownload:” then
tell application id “DNtp”
set theRecord to import thePath to incoming group
if exists theRecord then tell application “Finder” to delete theItem
end tell
end if
end try
end repeat
end if
end try
end adding folder items to

1 Like

The advice in this thread will show you the way:

1 Like

Thanks Korm, but due to my lack of Applescript experience I am struggling!

I have added these lines into the script

set theDatabase to open database “~/Library/Application Support/DEVONthink Pro 2/Inbox.dtBase2”

set theGroup to create location “/aaTEMP” in theDatabase

as follows:-

on adding folder items to this_folder after receiving added_items
	try
		if (count of added_items) is greater than 0 then
			tell application id "DNtp" to launch
			set theDatabase to open database "~/Library/Application Support/DEVONthink Pro 2/Inbox.dtBase2"
			set theGroup to create location "/aaTEMP" in theDatabase
			repeat with theItem in added_items
				try
					set thePath to theItem as text
					if thePath does not end with ".download:" and thePath does not end with ".crdownload:" then
						tell application id "DNtp" to import thePath to incoming group
					end if
				end try
			end repeat
		end if
	end try
end adding folder items to

BUT - when I compile I get a syntax error:-
Expected end of line, etc. but found “"”.

Also - do I need to change the line

tell application id “DNtp” to import thePath to incoming group

I don’t understand what variable is passing the destination path? Ie do I change “incoming group” to TheGroup

Any help with this would be appreciated.

Many Thanks

1 Like

Hi Korm - I am making some progress & have found that the script below works BUT…

  • it creates a NEW GROUP
  • once that is created it will then always use that GROUP

Is there a way to set the Destination Group to be an EXISTING GROUP in my database?

The modified script now looks like this

-- Action Import.applescript
-- DevonThink Pro
-- Created by Christian Grunenberg on Tue Dec 03 2002.
-- Copyright (c) 2002-2005. All rights reserved.
-- Modified by Karen Buckland on Wed Aug 02 2006.
-- Modified WPG 16.3.15

property pDestinationGroup : "Home/InBox Home/aatest2"

on adding folder items to this_folder after receiving added_items
	try
		tell application "DEVONthink Pro" to launch
		tell application "DEVONthink Pro" to set theDatabase to open database "/Macintosh HD/Users/garethmcclay/Document/Devonthink/Home.dtBase2"
		tell application "DEVONthink Pro" to set incomingGroup to create location pDestinationGroup
		repeat with theItem in every item of added_items
			try
				set thePath to theItem as text
				if thePath does not end with ".download" then
					if thePath does not end with ".p2p" then
						tell application "DEVONthink Pro" to import thePath to incomingGroup
					end if
				end if
			end try
		end repeat
	end try
end adding folder items to
1 Like

The syntax should be


tell application id "DNtp"
	set theDatabase to open database "~/Documents/DEVONthink Databases/ABC.dtBase2"
	set theGroup to create location "/Test Group" in theDatabase
	set theImport to import thePath to theGroup
end tell

This structure will only create a new group if the destination group does not exist, otherwise it will use the existing group at that path. The example is not meant to be pasted into your code. It’s a syntax example. Your code has too many nested “Tells” to DEVONthink. Also, for compatabilty with current and future DEVONthink releases you should use the “Tell” form shown in the example.

Hi Korm - many thanks for your reply. I have finally got there & my scripts seem to be working…

I’ll test over next few days & post up if they work consistently! (several times I thought I had everything working only to find a particular situation were the result was unexpected!)

As an applescript newbie, do you have a recommendation of a good book to learn applescript?
Also - how can I see a full list of related commands for DTPro / Applescript

Thanks again

Gareth

I’ve never finished any AppleScript book I’ve purchased. The best way to learn to code is to code. Examine scripts that do things you like, and learn from them. I find these two reference sites very helpful: MacScripter, and Mac OS X Automation. (The latter sells books and other tools in addition to the sample scripts.)

Use the “dictionary” function in Script Editor (Yosemite) or AppleScript Editor (pre-Yosemite).

1 Like

Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X (Third addition) by Hamish Sanderson and Hanaan Rosenthal is a great resource which starts right from the beginning and goes all the way through to very advanced examples

Its not so much that you read the book all at once but rather that you dip into it when you need to find out how to do something. It has a ton of useful illustrative examples which by themselves are useful snippets of things you may want to do.

You can obtain a listing of all the applescript commands that DT supports but honestly for a beginner its not very helpful. Applescript is very idiosyncratic and the best way to learn DT’s object model is to search this forum for the hundreds of good examples and, when you find one that is close to what you need to do, tear it apart line by line until you understand what each element does.

Frederiko

Thanks to Korm & Frederiko for your advice on Applescript books & learning.

In case anyone is interested, the final script which works looks like this:-



-- wpg_DTpro-Import&Delete to Home-MKto file    17.3.15
-- this imports into database stipulated and the group (folder) stipulated
-- to modify destination, only need to change the top 2 lines (property)
-- Original Created by Christian Grunenberg on Fri Mar 26 2010.
-- Copyright (c) 2010-2014. All rights reserved.
-- Modifed by GMcC to specify destination group



property pDatabase : "~/Documents/Devonthink/Home.dtBase2"
property pDestinationGroup : "/_MK to name & file"

on adding folder items to this_folder after receiving added_items
	try
		if (count of added_items) is greater than 0 then
			tell application id "DNtp" to launch
			repeat with theItem in added_items
				try
					set thePath to theItem as text
					if thePath does not end with ".download:" and thePath does not end with ".crdownload:" then
						tell application id "DNtp"
							set theDatabase to open database pDatabase
							set theGroup to create location pDestinationGroup in theDatabase
							set theRecord to import thePath to theGroup
							if exists theRecord then tell application "Finder" to delete theItem
						end tell
					end if
				end try
			end repeat
		end if
	end try
end adding folder items to


I use Hazel to analyse the files & this then moves the file to the appropriate Watch Folder where the script above moves the file into the Database/Group within Devonthink