I would like to import files into a DT database and have a metadata field that is a record of the location of the file was imported from on the MacOS filesystem. These particular files I am importing with ⌘ + dragging into the client and ideally would be able to continue doing this but obviously can compromise if I must.
All the automation I understand happens once the files are already imported and I’ve not seen anything that suggests the information I would like is still there to be worked with at this stage. I can conceptualise how I night do this (after getting my head around AppleScript…) by making a script that performed an import and carried the path across to fill the metadata field but even then it wouldn’t be a convenient way to import a large number of files distributed amongst a large number of folders.
An alternative is to index the files/folders, then copy their path to a custom metadata field and finally move the indexed items into the database (see Data > Move into Database)
Dragging in from any arbitrary location. They’re all over a variety of external drives and folders and I’m trying to consolidate. They’re mixed in with other files of the same format so dragging individually is essentially the only way to bring them in. Ideally the field would contain the complete path ie ‘/Volumes/extdrive1/dir/dir/dir/’. I’m not fussy about including the original filename in this path or not.
Create the Custom metadata, like importedfrom and write down the exact identifier. You can change the name of this field afterwards to human readable.
Copy this script and write the exact CMD identifier in add custom metadata line:
-- Script to move Selected Files from Finder to Selected Group in Devonthink
-- Created by Silverstone on 03.03.2021
-- Revised on 15.03.2021: correct deletion of imported folders
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application id "DNtp"
set theTags to {}
try
set theGroup to item 1 of (get selection)
if kind of theGroup is not "group" then set theGroup to current group
on error
set theGroupSet to display group selector "Select the Group to Import files from Path Finder" with tags
set theGroup to |group| of theGroupSet
set theTags to |tags| of theGroupSet
end try
tell application "Finder"
set FileList to (get selection)
repeat with theFile in FileList
set theFile to POSIX path of (theFile as alias)
tell application id "DNtp"
set theImported to import theFile to theGroup
add custom meta data theFile for "importedfrom" to theImported
log message info "File '" & proposed filename of theImported & "' was imported successfuly into '" & name of theGroup & "' of Devonthink. Source: '" & theFile & "' is deleted." record theImported
perform smart rule trigger import event record theImported
if theTags is not {} then
set theTags to theTags & (tags of theImported)
set tags of theImported to theTags
end if
end tell
do shell script "rm -R " & quoted form of theFile
end repeat
end tell
activate
end tell
Thanks for the script - an applescript would also be my solution
For the Devonthink import location (TheGroup) I would suggest simply using the default preferred import destination
and launch the script after selecting the files in Finder
My workflow is collection to the Global Inbox, and later processing
This is up to the user.
Usually, imported files do not stay in preferred import destination, you move them to the specific group. In most cases, in my workflow, the real destination is the currently open group or somewhere nearby (and it is easier to select it there than browse in chooser from scratch). So, you just run the script without extra manipulations.