AppleScript: shell scripts

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

  1. Tech198 macrumors G4

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

    lines like
    set posixPath to quoted form of POSIX path of fileToClean.
    do shell script "xattr -d " & 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

    Jun 4, 2009
    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

    Aug 9, 2009
    The 'xattr' command can list all the extended attributes on a file (or dir). It's the -l (lower-case ell, not digit one).
  4. Tech198 thread starter macrumors G4

    Mar 21, 2011
    Australia, Perth
    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

    Nov 15, 2013
    Seattle Area (NOT! Microsoft)
    The 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 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

    Aug 9, 2009
    The name of the extended attribute is "". 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 "".

    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 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.

    MP3 and some other audio files can have ID3 tags stored in the file itself.

    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'.

    '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.

    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 "" 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

    Nov 15, 2013
    Seattle Area (NOT! Microsoft)

Share This Page