Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created May 2, 2014
Embed
What would you like to do?
A Sentaku-based wrapper for mdfind
#!/usr/bin/ruby
require 'shellwords'
query = ARGV.length > 0 ? ARGV.join(" ") : "date:today"
files = %x{mdfind '#{ARGV.join(" ")}'}.split("\n")[0..100]
filehash = {}
files.each {|file|
base = File.basename(file)
dir = File.dirname(file)
filehash["#{base} (#{dir})"] = file
}
menu = filehash.keys.join("\n")
res = %x{echo #{Shellwords.escape(menu)}|#{File.dirname(__FILE__)}/sentaku -s "line"}
unless res == ""
print "What command? (Enter to `open`): "
command = STDIN.gets.chomp
command = "open" if command == ""
puts %x{#{command} #{Shellwords.escape(filehash[res])}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment