- 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?