Hej there,
I’m trying to set up a system to have Hazel automatically move a file into a specific DT folder.
I am a newbie and know only a little bit about scripting.
I found this info (http://www.noodlesoft.com/forums/viewtopic.php?f=3&t=4694).
As described there 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…
----------------- my modified script from the source i gave the link above -------
!/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”
echo $matches
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” ~/HazelAutomation/4.HazelBackup/.
exit
--------- End of script -------------
I would appreciate any suggestions. Thanks!