Created
October 19, 2009 02:02
-
-
Save lamdor/213024 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| IGNORABLE = ["script", "Icon\r", "SPOTLIGHT_TAGS"] | |
| files = Dir["*"] - IGNORABLE | |
| def spotlight_cmd(file) | |
| `xattr -p com.apple.metadata:kMDItemFinderComment "#{file}"`.gsub("\n", " ") | |
| end | |
| def hex_sequence_to_s(hex_seq) | |
| hex_seq.split(" ").map do |hex| | |
| hex.to_i(16).chr | |
| end.join | |
| end | |
| def spotlight_comment_portion(s) | |
| s.gsub(/bplist[^&]+(.*)[\b].*/, "\\1") | |
| end | |
| def spotlight_comments_for(file) | |
| spotlight_comment_portion(hex_sequence_to_s(spotlight_cmd(file))) | |
| end | |
| if __FILE__ == $0 | |
| files.each do |f| | |
| # p [:file, f] | |
| puts("%s -> %s" % [f, spotlight_comments_for(f)]) | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment