Hazel and DevonThink - Sending/import PDF-files to DT

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Hello there,

i started my question in the DevonThink-Forum http://forum.devontechnologies.com/viewtopic.php?f=20&t=22965&p=111199#p111199, where "korm" referenced me to ask here will be the better idea..

Ok...
I want to sort my pdf-files automatically with hazel and give them to a special folder to DT.
In the noodlesoft-forum i found this Link: http://www.noodlesoft.com/forums/viewtopic.php?f=3&t=4694 where i found what i want to do.
"only" a little bit to adjust the script and go.... But sorry, as a newbie in scripting, it doesn´t work for me... :o :oops:

As described i tried to modify that script for my environment, but i only get an unspecific error from hazel working with my modified script.
But i don´t know why.
I created a test-Database in DT.
I created a group called "Finanzen"
I want Hazel - with help of the script on matching the filename "Kontoauszug.pdf"- that the file comes to DT and was sorted into the Group "Finanzen".
I do not get a file called log.txt.

The error message i get form hazel is: "Shell script failed. Error processing shellscript on "Kontoauszug.pdf"".

Can´t figure out, where my fault is.... :shock:


Here is my adjusted script:
---------
!/bin/sh

# This script moves files of to DevonThink folders automatically
# based on the $Matches variable.
#
# It looks for a match in the PDF File Name, and moves the file to
# the corresponding DevonTHINK Folder Name.
#
# If it does not find a match, it copies the file to the Inbox.
#
# In either case, it moves the file to the Backup folder
#
# use this pattern to match files: PDFFileName|DevonTHINKFolderName



Matches="Kontoauszug|/Finanzen"






IFS=$'\n' read -rd '' -a MatchNames <<<"$Matches"

FullPath=`echo "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"`

echo `date` > ~/HazelAutomation/log.txt
echo "Looking in [$1] for:" > ~/HazelAutomation/log.txt

j=0
for i in "${MatchNames[@]}"
do
IFS=$'|' read -rd '' -a GroupNames <<<"${MatchNames[$j]}"

MatchString=${GroupNames[0]}
FolderName=$(echo ${GroupNames[1]}) #use this to remove trailing new line character

echo $j "["$MatchString"]" >> ~/HazelAutomation/log.txt
echo "$1" | grep -q "$MatchString"
greprc=$?
if [[ $greprc -eq 0 ]] ; then
echo "Found:[$MatchString] in [$1] moving to [$FolderName]" >> ~/HazelAutomation/log.txt
Command='
tell application id "com.devon-technologies.thinkpro2"\n
launch\n
set theDatabase to open database "/Volumes/LWD_20160523/02_DevonThink/test/test.dtBase2"\n
set theGroup to create location "'$FolderName'" in theDatabase\n
import "'$FullPath'" to theGroup\n
end tell\n
'
echo $Command >> ~/HazelAutomation/log.txt
echo $Command | osascript
mv "$FullPath" ~/HazelAutomation/4.HazelBackup/.
exit
fi
let "j++"
done
echo "No match found for $1" >> ~/HazelAutomation/log.txt
cp "$FullPath" "/Users/rolf/Library/Application Support/DEVONthink Pro 2/Inbox/."
mv "$FullPath" /Volumes/LWD_20160523/Temp/Hazel/Hazel_2_DT/04_HazelBackup/.
exit
----------------


I would appreciate any suggestions.
Thanks for your feedback in advance.
Happy wife .... Happy life... :D
HaubenTaucher
 
Posts: 19
Joined: Sun Oct 23, 2016 8:23 am
Location: Germany / OWL

I suggest you reply to the author who posted the script as this is outside the support I can give.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support