Skip to content

Instantly share code, notes, and snippets.

@lamdor
Created October 19, 2009 02:02
Show Gist options
  • Select an option

  • Save lamdor/213024 to your computer and use it in GitHub Desktop.

Select an option

Save lamdor/213024 to your computer and use it in GitHub Desktop.
#!/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