Page 1 of 1

help with rule set up

PostPosted: Sat Aug 04, 2012 9:26 pm
by ano
I'm trying to create a rule that will read the content for the pdf and move it to the correct folder base on the date found. I use the following applescript to create the custom tokens:

Code: Select all
set itemPath to quoted form of POSIX path of theFile
set res to do shell script "/usr/local/bin/pdftotext " & itemPath & " - | awk '/through/{print $7, $5}; NR == 10 {exit}'"
return {hazelExportTokens:{ctkYear:word 1 of res, ctkMMM:word 2 of res}}


The token ctkYear returns the 4 digit year and ctkMMM returns the month spelled out (i.e. "July", "May", "April", etc). I then use "Sort into subfolder" with the custom token to move the file into subfolder "yyyy/mm"

Since I wanted the folder to be numeric, I added "Replace text" for the token "ctkMMM" to convert the month into digits (i.e "July" -> 07).

However, it is not picking up the replace text at all and keep moving the the file into folder "May" instead of "05". I also noticed in the log file that it's complaining about "bad file descriptor".

2012-08-04 17:27:52.412 hazelworker[9336] DEBUG: AppleScript executed successfully with file /Users/username/Documents/Paperwork/StatementPdfaa.pdf. Result: <NSAppleEventDescriptor: { 'usrf':[ 'utxt'("hazelExportTokens"), { 'usrf':[ 'utxt'("ctkYear"), 'utxt'("2012"), 'utxt'("ctkMMM"), 'utxt'("May") ] } ] }>
2012-08-04 17:27:52.475 hazelworker[9336] DEBUG: Error closing lock on destination /Users/username/Documents/Paperwork/2012/StatementPdfaa.pdf: Bad file descriptor
2012-08-04 17:27:52.475 hazelworker[9336] [File Event] File moved into subfolder: /Users/username/Documents/Paperwork/2012/StatementPdfaa.pdf sorted from folder /Users/username/Documents/Paperwork to subfolder 2012.
2012-08-04 17:27:52.501 hazelworker[9336] DEBUG: Error closing lock on destination /Users/username/Documents/Paperwork/2012/May/StatementPdfaa.pdf: Bad file descriptor
2012-08-04 17:27:52.501 hazelworker[9336] [File Event] File moved into subfolder: /Users/username/Documents/Paperwork/2012/May/StatementPdfaa.pdf sorted from folder /Users/username/Documents/Paperwork/2012 to subfolder May.
2012-08-04 17:27:52.533 hazelworker[9336] DEBUG: Error closing lock on destination /Users/username/Documents/Paperwork/2012/May/stat_chase_2012May.pdf: Bad file descriptor


What am i doing wrong?

Re: help with rule set up

PostPosted: Mon Aug 06, 2012 3:58 pm
by Mr_Noodle
You should do the substitution in the script if possible. Exported tokens are shown as-is and ignores any formatting you do in Hazel. There were issues before when Hazel did format exported tokens so the code path was changed so that it short-circuited all that.