Renaming a PDF based on metadata

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

Moderator: Mr_Noodle

Renaming a PDF based on metadata Sun Jul 15, 2012 3:42 pm • by dworsham
I've got an AppleScript that parses the metadata for a downloaded pdf statement to get the statement data (as opposed to the download date). It seems to work when run externally. When my rule executes, I get a Console entry stating that it could not find the file. I'm sure it's something stupid I'm overlooking but, after a couple of hours, I don't see it.

Here's my applescript that returns a token that would be used by the next action to rename the file:
Code: Select all
set whereFrom to "kMDItemWhereFroms"
set theMetadata to (do shell script "mdls -name kMDItemWhereFroms " & theFile)

set tid to AppleScript's text item delimiters

set AppleScript's text item delimiters to whereFrom & " = ("
set theUrl to (text item 2 of theMetadata)

..a bunch of other parsing statements
set formattedDate to theYear & "-" & theMonth

return {hazelExportTokens:{statementDate:formattedDate}}


This is the only action for my rule. I get the following in the Console as a result:
2012-07-15 14:39:27.626 hazelworker[30279] AppleScript error: {
NSLocalizedDescription = "SSD:Users:David:Dropbox:Actions:statement.pdf: could not find SSD:Users:David:Dropbox:Actions:statement.pdf.";
dworsham
 
Posts: 6
Joined: Sun Jul 15, 2012 3:33 pm

Re: Renaming a PDF based on metadata Sun Jul 15, 2012 4:14 pm • by dworsham
Nothing fails to produce an answer to your own question like posting the question...

Looks like all I needed was
Code: Select all
set currentFile to quoted form of POSIX path of (theFile)
set theMetadata to (do shell script "mdls -name kMDItemWhereFroms " & currentFile)
dworsham
 
Posts: 6
Joined: Sun Jul 15, 2012 3:33 pm


Return to Support