-- DEVONthink - Index.applescript
-- Created by Christian Grunenberg on Tue Feb 17 2004
-- Copyright (c) 2002-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" to indicate thePath to incoming group
end if
end try
end repeat
end if
end try
end adding folder items to
Replace the line after "if thePath does not end with “.download:” and thePath does not end with “.crdownload:” then
" with…
if (name of databases) contains "scans" then
tell application id "DNtp" to indicate thePath to incoming group of database "scans"
else
display alert "The scans database isn't open."
end if
This doesn’t open the database, though that’s certainly possible. It either works since the database is open or it warns you the database isn’t open.
Thanks!
There seems to be a minor error but I can’t seem to pinpoint it:
-- DEVONthink - Index.applescript
-- Created by Christian Grunenberg on Tue Feb 17 2004
-- Copyright (c) 2002-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
if (name of databases) contains "scans" then
tell application id "DNtp" to indicate thePath to incoming group of database "scans"
else
display alert "The scans database isn't open."
end if
end try
end repeat
end if
end try
end adding folder items to
try
set thePath to theItem as text
if thePath does not end with ".download:" and thePath does not end with ".crdownload:" then
if (name of databases) contains "scans" then
tell application id "DNtp" to indicate thePath to incoming group of database "scans"
else
display alert "The scans database isn't open."
end if
end if
end try
You were missing the final “end if”
Be aware that if “scans” is not open, or if DEVONthink is not open, then the folder will accumulate the files and they will not appear in any database.
Rather than using a folder action to cause DEVONthink to index files to a specific database, just index that folder in that database. You’ll get better results. This is not a good use of folder actions, in my opinion.
How do I go about to achieve that?
Goal is to index each file to the database as it gets added to the folder.
That’s why I set out to do this as a folder action.
So, you understand that “indexing a file to a database” means the actual file remains in the external file, and the database “knows about” the file and can search it, but the database does not contain the file? That is – indexing is the opposite of importing.
If it is indexing that you really want to do, then open the database (i.e., your “scans” database), and choose File > Index. You will be prompted to choose the external folder you want to index. Then you’re done. As you add files to the external folder, then select the group in the database where the index was placed, the database will be updated with indexed instances of the files from the folder. Again – this is indexing, not importing.
I’m glad that works for you, Erwin. There’s no auto-update for indexed groups built into DEVONthink at this time. There’s the global File > Update Indexed Items command which operates on all indexed groups in a database. Apart from that, indexing auto-update would have to be handled via a script or cron job or something.
In the dark ages, before iCal calendars were moved to iCloud, we could attach AppleScripts to calendar events and I had a recurring event with a script that would do this update. It was a kludge and never worked well.