Hi,
It is not an imported, it is an indexed file. I have solved the issue by exporting the pdf and re-indexing it from its new location. Not very elegant but it works.
I read and annotate my research articles on a large eInk reader (Sony DPT-RP1). I have all files organized in a folder structure according to main subject in a google drive folder. I sync this folder with the DPT-RP1.
When I find a new article I import it to Bookends. A folder-action script i[/i] automatically imports it to the inbox of a predefined DT library. When the article is selected in DT a triggered script i[/i] forces me to classify it to a group and then creates the corresponding folder on the disk and moves the pdf. If I want to move an article within the DT library I use a script i[/i] from the script menu of DT to do this. SCRIPT_4 is a helper script.
The scripts also set the metadata of the PDF file using exiftool and create URL cross-references between Bookends and DT.
Edit 1: Minor change to SCRIPT_4 for handling single quotes in exiftool arguments
SCRIPT_1
property MyDatabase : "name_of_database_to_index_into"
property FilingScript : "path_to_script_2"
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
local theFileName
local thePath
repeat with theItem in added_items
try
set thePath to theItem as text
tell application "System Events" to set theFileName to name of disk item thePath
-- The next line evaluates if the file is of format "a (d) - t." or "a - t. (d)" ¬
-- which I use for books and articles respectively.
-- This avoids indexing files that are not properly named
set shellScript to "[[ " & quoted form of theFileName & " =~ (^.*\\([[:digit:]]{4}\\)[[:space:]]-[[:space:]].*)|(^.*[[:space:]]-[[:space:]].*\\([[:digit:]]{4}\\))\\.pdf$ ]]; printf $?"
set isMatch to "0" = (do shell script shellScript)
if isMatch then
tell application id "DNtp"
set theImportedItem to indicate thePath to incoming group of database MyDatabase
set theImportedItem's attached script to FilingScript
end tell
else
display notification "Offending file: " & quoted form of theFileName with title "File not imported to DevonThink" subtitle "Wrong format."
end if
on error errStr number errorNumber
error errStr number errorNumber
end try
end repeat
end if
end try
end adding folder items to
SCRIPT_2
property MoveRecordsScript : "path_to_script_3"
on triggered(ignore_me)
run script MoveRecordsScript
end triggered
SCRIPT_3
property MyDatabase : "name_of_database_to_index_into"
property IndexedFolder : "the_path_to_the_watched_folder"
property queryBookendsScript : "path_to_script_4_(use an AppleScript path with semicolons"
on run
tell application id "DNtp"
set theGroup to display group selector for database MyDatabase
set destFolder to IndexedFolder & the location of theGroup & the name of theGroup
set selectedItems to selection
repeat with a from 1 to length of selectedItems
-- set the variables
set theRecord to item a of selectedItems
set theFileName to name of theRecord
set destPath to destFolder & "/" & theFileName
set origPath to theRecord's path
set refNo to (load script file queryBookendsScript)'s queryBookends(theFileName, origPath)
-- do the work
export record theRecord to destFolder
tell application "System Events"
delete alias (destFolder & "/DEVONtech_storage")
delete alias origPath
end tell
delete record theRecord
set theReImportedRecord to indicate destPath to theGroup
set theReImportedRecord's unread to false
set refURL to theReImportedRecord's reference URL
if refNo is not "" then
set theReImportedRecord's URL to "bookends://sonnysoftware.com/" & refNo
tell application "Bookends"
«event ToySSFLD» refNo given «class FLDN»:"keywords", string:name of theGroup
«event ToySSFLD» refNo given «class FLDN»:"url", string:refURL
end tell
end if
end repeat
end tell
end run
SCRIPT_4
on queryBookends(theFileName, thePath)
-- * ? + [ ( ) { } ^ $ | \ . must be escaped in Bookends SQL
-- I do not escape . as it is not needed :)
-- Add more characters to escape if you come across them in your filenames
-- Use the "ASCII-only names" option in Bookends to avoid other special characters
set fileNameRegExp to replaceText("(", "\\(", theFileName)
set fileNameRegExp to replaceText(")", "\\)", fileNameRegExp)
set fileNameRegExp to replaceText("[", "\\[", fileNameRegExp)
set fileNameRegExp to replaceText("]", "\\]", fileNameRegExp)
-- I have found no way to escape single quote in Bookends SQL search
-- I substitute it with . (<any character>)
set fileNameRegExp to replaceText("'", ".", fileNameRegExp)
set fileNameRegExp to quoted form of fileNameRegExp
set RegExp to "attachments REGEX " & fileNameRegExp
tell application "Bookends" to set RefNo to «event ToySSQLS» RegExp
if RefNo is not "" then
tell application "Bookends"
set pdfTitle to quoted form of («event ToySRFLD» RefNo given string:"title")
set pdfAuthor to quoted form of («event ToySRFLD» RefNo given string:"authors")
set pdfDate to quoted form of («event ToySRFLD» RefNo given string:"thedate")
end tell
-- exiftool to write PDF metadata, may fail for various reasons
try
do shell script "/usr/local/bin/exiftool -overwrite_original -Title=" & pdfTitle & " -Author=" & pdfAuthor & " -Copyright=" & pdfDate & " " & quoted form of thePath
end try
else
display notification "Offending file: " & quoted form of theFileName with title "Not found in Bookends Library"
end if
return RefNo
end queryBookends
on replaceText(find, replace, someText)
set localOldDelims to AppleScript's text item delimiters
set text item delimiters of AppleScript to find
set someText to text items of someText
set text item delimiters of AppleScript to replace
set someText to "" & someText
set text item delimiters of AppleScript to localOldDelims
return someText
end replaceText