0

Trying to add the "Where from" metadata in the Finder's "Get info" section of a picture on the Desktop and I am not able to since the text has special characters.

In this case, it is "?" and "=" that are present in "theURL_1". As you can see, I have removed these characters on "theURL_2" and it works just fine.

What would be the solution to include the full URL in the metadata?

set theFile to POSIX path of (path to desktop folder) & "cat.jpg"

set theURL_1 to "https://www.youtube.com/watch?v=EtH9Yllzjcc"
set theURL_2 to "https://www.youtube.com/watchvEtH9Yllzjcc"

do shell script "xattr -w 'com.apple.metadata:kMDItemWhereFroms' " & quoted form of theURL_1 & space & quoted form of theFile
5
  • AIUI that xattr is supposed to hold a binary property list data structure, not a plain string. It appears it sometimes tolerates a plain string, but not always. Commented May 3, 2020 at 21:00
  • Thanks for the reply. So what you saying is that it is not possible to add the Youtube URL to the where from metadata using my approach? I ask because I have seen other applications add it without an issue. What method should be used to accomplish this?
    – David
    Commented May 3, 2020 at 22:11
  • Your script does work, the whereFroms attribute is added, it apparently just doesn't show up in the Get Info window (it doesn't in my Mojave test anyway). As mentioned, maybe the Finder is expecting a property list - to give that a try, check out my answer to a similar topic (note that the script is expecting a list of input file items).
    – red_menace
    Commented May 3, 2020 at 22:24
  • @red_menance, how do you know it was added? It is not even showing up in my Display Metadata List script: (set theFile to choose file do shell script "mdls " & quoted form of POSIX path of theFile)
    – David
    Commented May 4, 2020 at 23:02
  • I cheat and use a utility that I wrote, but from Terminal you can use ls -ld@ /path/to/file to show extended attributes, and xattr -p com.apple.metadata:kMDItemWhereFroms /path/to/file to get the value of the whereFroms attribute (if it is there).
    – red_menace
    Commented May 7, 2020 at 14:52

0

You must log in to answer this question.

Browse other questions tagged .