Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Tech198

Cancelled
Original poster
Mar 21, 2011
15,915
2,151
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.
 

cqexbesd

macrumors regular
Jun 4, 2009
175
42
Germany
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>

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

chown33

Moderator
Staff member
Aug 9, 2009
10,731
8,407
A sea of green
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...
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
 
  • Like
Reactions: CreatorCode

Tech198

Cancelled
Original poster
Mar 21, 2011
15,915
2,151
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
 

Attachments

  • Screen Shot 2016-07-09 at 12.24.11 am.png
    Screen Shot 2016-07-09 at 12.24.11 am.png
    25.2 KB · Views: 188

jasnw

macrumors 65816
Nov 15, 2013
1,012
1,048
Seattle Area (NOT! Microsoft)
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.
 
Last edited:

chown33

Moderator
Staff member
Aug 9, 2009
10,731
8,407
A sea of green
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..
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.


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..
What did you adjust it to? Post the exact command line you used. Also post the exact output, if any, including any error messages.


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

but it didn't work
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.