AppleScript: shell scripts

Discussion in 'Mac Programming' started by Tech198, Jul 7, 2016.

  1. Tech198 macrumors G4

    Joined:
    Mar 21, 2011
    Location:
    Australia, Perth
    #1
    I'm trying to learn a bit more about shell scripts specifally more about what xattr can do..

    lines like
    Code:
    set posixPath to quoted form of POSIX path of fileToClean.
    do shell script "xattr -d com.apple.metadata:kMDItemWhereFroms " & posixPath
    I'm trying to understand which points it refers to in the selected file, so i can adapt the code/add for further for my own users..

    All i've found so far online is what POIX and xattr do, not what they can reference..

    eg... "Where from" tag in Get info of selected video fille meaning xattr and KMD<tag name from get info>

    sorta thing..... Once i understand this, the rest should be easy...

    basically, i'm trying to find out where xattr knows where is by name or some reference point i can latch on to.

    Any help would be appreciated.
     
  2. cqexbesd macrumors regular

    Joined:
    Jun 4, 2009
    #2
    xattr is just a command to set the extended attributes on a file. You can use it against any file on a supported file system (e.g. HFS+). Do you mean you want a list of the extended attribute in use under OSX? If so I don't have one but maybe someone else will...or Google...
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    The 'xattr' command can list all the extended attributes on a file (or dir). It's the -l (lower-case ell, not digit one).

    https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/xattr.1.html
     
  4. Tech198 thread starter macrumors G4

    Joined:
    Mar 21, 2011
    Location:
    Australia, Perth
    #4
    Maybe i'm coming from wrong direction.....

    I'm trying to find out what anything that comes after KDMItem if it refers to anything .... ie,, does WhereFroms refer to a tag name "Where from:" or what ? how does it get this tag if its not coded ? etc..

    Once i know this., i can adjust it to my needs. But its the only thing i'm stuck on.

    I tried adjusting the WhereFroms to my own tag name, but noting happened..

    For example using shell script from code to delete "Author" tag in a music file. so I had KDMItemAuthor ,,

    but it didn't work
     

    Attached Files:

  5. jasnw, Jul 8, 2016
    Last edited: Jul 8, 2016

    jasnw macrumors 6502

    Joined:
    Nov 15, 2013
    Location:
    Seattle Area (NOT! Microsoft)
    #5
    The com.apple.metadata:kMDItemWhereFroms in your sample is the name of an attribute that has been assigned to a file. You need to know the name of the specific extended attribute you want to remove from the fileToClean file, and then use that name after the '-d' replacing the entire com.apple....Froms string. Using "xattr -l filename" as suggested earlier will give you a complete list of the extended attributes assigned to that file.

    Are you sure that what you want to modify is an extended attribute? I just looked at a few music files (m4a and m4p) and the only extended attributes I see are related to Finder. Author sounds more like metadata that would be embedded in the music file itself rather than an extended attribute, which would be accessed via some other mechanism.
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    The name of the extended attribute is "com.apple.metadata:kMDItemWhereFroms". You may think that only "WhereFroms" is the tag or attribute, but this would be wrong. The simple fact is that Apple has defined an extended attribute with a name of "com.apple.metadata:kMDItemWhereFroms".

    Use the -l option of the 'xattr' command to list all the extended attributes attached to a file.

    I don't know of any comprehensive list of all possible xattr attribute names. The simple fact here is that an attribute name can be anything. There is a name-length limit, but I don't recall what it is. The man page entries for getxattr, setxattr, etc. may tell you. There are links to those man pages in the SEE ALSO section at the bottom of the link I posted above. You should probably read those so you understand exactly what an xattr is, and what its limitations are.

    Apple has defined some xattr names, and other vendors may also use whatever they want. There isn't a central authority managing or assigning attribute names. There is a recommendation for defining your own names, but that's it.

    The format of the com.apple.metadata:kMDItemWhereFroms data is a binary plist. You can google binary plist to learn more.


    What did you adjust it to? Post the exact command line you used. Also post the exact output, if any, including any error messages.


    Xattrs are not the only place that "extra info" or "metadata" is stored.

    Images can have EXIF data stored in the file itself.
    https://en.wikipedia.org/wiki/Exchangeable_image_file_format

    MP3 and some other audio files can have ID3 tags stored in the file itself.
    https://en.wikipedia.org/wiki/ID3

    Other files may have additional forms, often stored in the file itself, but sometimes stored in the file's resource fork.


    If you want to retrieve more extensive metadata for a file, you may be better off using the 'mdls' command, rather than 'xattr'.
    https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/mdls.1.html

    'mdls' queries the Spotlight metadata, and Spotlight knows about ID3, EXIF, and other tagging formats. Spotlight extracts this metadata and stores it in a unified metadata store, the Spotlight database.

    There is developer info on Spotlight queries.
    https://developer.apple.com/library...tual/SpotlightQuery/Concepts/QueryFormat.html

    You can also find examples by googling spotlight queries.


    One difference between Spotlight metadata and xattrs is that Spotlight metadata is read-only.

    Xattrs can be set using command-line tools, such as changing or removing a "com.apple.metadata:kMDItemWhereFroms" attribute. However, you can't change or remove the Spotlight metadata except by changing the xattr on the file itself.

    As another example, you can't change the Author tag for an audio file if that's stored in an ID3 tag. You'd need to obtain a command-line tool for changing ID3 tags. Such tools exist; you can google for them.
     
  7. jasnw macrumors 6502

    Joined:
    Nov 15, 2013
    Location:
    Seattle Area (NOT! Microsoft)

Share This Page