Skip to content

Instantly share code, notes, and snippets.

@youpy
Created February 18, 2010 21:01
Show Gist options
  • Select an option

  • Save youpy/308064 to your computer and use it in GitHub Desktop.

Select an option

Save youpy/308064 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'spotlight'
require 'fileutils'
include FileUtils::Verbose
if ARGV.size < 2
warn "usage: {$0} /path/to/foo.savedSearch /path/to/dest_dir [ln | mv | cp | ln_s]"
exit 1
end
saved_search, dest_dir, behavior = ARGV
behavior = 'ln_s' unless behavior
unless File.exists?(dest_dir)
mkdir_p dest_dir
end
query = Spotlight::Query.from_saved_search(saved_search)
query.execute.each do |item|
path = item.get(:kMDItemPath)
unless File.exists?(File.join(dest_dir, File.basename(path)))
send(behavior, path, dest_dir) if File.file?(path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment