Re: Autofile from Hazel -> OCR (PDFPenPro) -> DevonThink
Posted: Tue Dec 27, 2016 5:57 pm
For completeness sake, my modified script:
-----------------------------------------------------
Matches="Cleaners|/Utilities/Cleaners
Phone|/Utilities/Phone
Bank|/Finance/Bank
Cable|/Utilities/Cable
Community Giving|/Charity/Community Giving
Paystub|/Employment/My Employer
mc_0170|/mc_0170
mc_7814|/mc_7814"
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 "/Users/erwin/DT_bases/MyScans.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/erwin/Library/Application Support/DEVONthink Pro 2/Inbox."
mv "$FullPath" ~/HazelAutomation/4.HazelBackup/.
exit
-----------------------------------------------------
Matches="Cleaners|/Utilities/Cleaners
Phone|/Utilities/Phone
Bank|/Finance/Bank
Cable|/Utilities/Cable
Community Giving|/Charity/Community Giving
Paystub|/Employment/My Employer
mc_0170|/mc_0170
mc_7814|/mc_7814"
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 "/Users/erwin/DT_bases/MyScans.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/erwin/Library/Application Support/DEVONthink Pro 2/Inbox."
mv "$FullPath" ~/HazelAutomation/4.HazelBackup/.
exit