I’ve googled and searched all day in script forums and could not find a script that could do this. I grabbed pieces from a few scripts I found in forums and tried to make one without applescript knowledge. I managed to rename one file based on the “Where From” in the Finder “Get Info” window. But obviously, the script is faulty. I am hoping someone can help me sort it out. I need to batch rename hundreds of files with the URL in the “Where From” info. Here’s the script.
-- get Spotlight kMDItemWhereFroms attribute
property getSpecific : true -- show the specific download URL?
set theFile to (choose file)
set aFile to quoted form of POSIX path of theFile
set theURL to (do shell script "mdls -name kMDItemWhereFroms -raw " & aFile)
if theURL is "(null)" then -- no attribute
set theURL to "(URL info not found)"
set theMessage to ""
else
if getSpecific then -- get the first item (the download URL)
set theURL to paragraph 2 of theURL
set here to offset of "\"" in theURL
set theURL to text (here + 1) thru -3 of theURL -- the download URL
tell application "Finder"
set name of theFile to theURL --I have no idea what im doing
end tell
else -- get the last item (the page/site URL)
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
Model: MacPro
AppleScript: 2.2.1
Browser: Safari 537.1
Operating System: Mac OS X (10.7)