So, plenty of times, I download files that have more information in their “Where From” property than they do in the actual filenames. For example, the statements that I get from my bank, carry my full account number and date of statement in the “Where From” property, but the filename only contains my bank identifier plus a random number. So I wrote this script (using snippets from many different sources, of course) to batch rename a selection in the Finder based on the Where From property. Just make a selection in the Finder, be it a single file or 200, and run this script. You could also use Automator to create a Service out of this script and assign a keyboard shortcut for accessibility. See this page for a step-by-step on how to do that.
So, here’s the script:
property getSpecific : true tell application "Finder" set FileList to selection as alias list set x to number of items in FileList end tell set i to 1 repeat while i is less than (x + 1) tell application "Finder" set theFile to item i of FileList set aFile to quoted form of POSIX path of (item i of FileList) end tell set theUrl to (do shell script "mdls -name kMDItemWhereFroms -raw " & aFile) if theUrl is "(null)" then set theUrl to "(URL info not found)" set theMessage to "" else if getSpecific then set here to offset of "\"" in theUrl set nameArray to my theSplit(theUrl, "/") set newName to last item of nameArray set newName to paragraph 1 of newName set newName to text 1 thru -3 of newName tell application "Finder" try set name_ext to name extension of theFile set name of file theFile to newName & "." & name_ext on error error_message number error_number if error_number = -48 then set name of file theFile to newName & "-" & i & "." & name_ext else activate display dialog error_message & " " & error_number end if end try end tell else set theMessage to "page/site " set theUrl to paragraph -2 of theUrl set here to offset of "\"" in theUrl set theUrl to text (here + 1) thru -2 of theUrl end if end if set i to i + 1 end repeat on theSplit(theString, theDelimiter) set oldDelimiters to AppleScript's text item delimiters -- set delimiters to delimiter to be used set AppleScript's text item delimiters to theDelimiter set theArray to every text item of theString set AppleScript's text item delimiters to oldDelimiters return theArray end theSplit
We choose to be influenced. We can’t choose how.