re extracting dates from PDFs

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

Moderator: Mr_Noodle

re extracting dates from PDFs Wed Oct 21, 2015 4:29 am • by jaykay2279
Hi Im trying to extract dates from PDF's to rename my files accordingly

Im running this script and get this error

Im trying to do this but I keep getting an error.

My script is this

set itemPath to quoted form of POSIX path of theFile
set dateString to do shell script "/usr/local/bin/pdftotext " & itemPath & " - | awk 'NR < 2 {print $1, $8}'"
set stmMonth to word 1 of dateString
if stmMonth is "January" then
set stmMonth to "01"
else if stmMonth is "February" then
set stmMonth to "02"
else if stmMonth is "March" then
set stmMonth to "03"
else if stmMonth is "April" then
set stmMonth to "04"
else if stmMonth is "May" then
set stmMonth to "05"
else if stmMonth is "June" then
set stmMonth to "06"
else if stmMonth is "July" then
set stmMonth to "07"
else if stmMonth is "August" then
set stmMonth to "08"
else if stmMonth is "September" then
set stmMonth to "09"
else if stmMonth is "October" then
set stmMonth to "10"
else if stmMonth is "November" then
set stmMonth to "11"
else if stmMonth is "December" then
set stmMonth to "12"
end if
return {hazelExportTokens:{stmMonth:stmMonth, StmYear:word 2 of dateString}}


Tokens are stmMonth and stmYear

I get this error

2015-10-21 09:16:25.842 hazelworker[2204] Untitled.pdf: Rule Natwest Credit Card Statements matched.
2015-10-21 09:16:25.916 hazelworker[2204] [Error] AppleScript failed: Error executing AppleScript on file /Users/jameskelly/Google Drive/Scans/Untitled.pdf.
2015-10-21 09:16:25.917 hazelworker[2204] OSAScript error: {
NSLocalizedDescription = "Can\U2019t get word 1 of \"\".";
NSLocalizedFailureReason = "Can\U2019t get word 1 of \"\".";
OSAScriptErrorAppAddressKey = "<NSAppleEventDescriptor: null()>";
OSAScriptErrorBriefMessageKey = "Can\U2019t get word 1 of \"\".";
OSAScriptErrorMessageKey = "Can\U2019t get word 1 of \"\".";
OSAScriptErrorNumberKey = "-1728";
OSAScriptErrorOffendingObjectKey = "<NSAppleEventDescriptor: 'obj '{ 'form':'indx', 'want':'cwor', 'seld':1, 'from':'utxt'(\"\") }>";
OSAScriptErrorRangeKey = "NSRange: {0, 0}";


Any ideas or help

Thanks

James
jaykay2279
 
Posts: 2
Joined: Thu Oct 15, 2015 4:51 am

Re: re extracting dates from PDFs Wed Oct 21, 2015 1:53 pm • by Mr_Noodle
Try running the script outside of Hazel. I'm guessing by the error, it has to do with this line:
Code: Select all
set stmMonth to word 1 of dateString

Also, is there a reason you are using a script for this instead of using a custom date attribute?
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron