Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a command that can tell the label status (labels as applied in the info menu in the finder cmd+i) of an item from the command-line in OS X? Essentially, I just want to list all the items with or without labels in the current directory, but I can't find any way to pull them appart.

This will help in creating a timed script that runs in the background. Then I can apply a label in finder and expect an action automatically apply to that file without having to make special conditions or keep a curated file with a list.

share|improve this question
up vote 3 down vote accepted

Using ls, you can show the extended metadata of files:

$ ls -l@
-rw-r--r--@ 1 andrew  staff  1292910 Aug  9 11:36 labelled_file.jpg       50 

However, the quickest way to get labelled and unlabelled files is with an attribute search using mdfind:

$ mdfind -onlyin . -literal 'kMDItemFSLabel > 0'  # labels have value 50

$ mdfind -onlyin . -literal 'kMDItemFSLabel == 0'
share|improve this answer
Thanks a lot, I ended up using this for my solution :) – scicalculator Nov 25 '11 at 7:06

You can use

xattr -p filename

but you will need some work to process the output. See this answer on superuser for an example with a bash script and one with Python.

share|improve this answer
Your reference was very helpful, thanks! – scicalculator Nov 25 '11 at 7:06
@dat5h if you find an answer useful please give an up vote and choose one of the answers as 'accepted' – Matteo Nov 25 '11 at 10:59
Thanks for reminding me to mark-as-accepted, I had forgotten. Also, I'd give upvotes if I had the reputation required. – scicalculator Nov 28 '11 at 4:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.