16
17
18
19
20
21
22
23
24
25
|
# File 'lib/searchlink/searches/spotlight.rb', line 16
def search(_, search_terms, link_text)
query = search_terms.gsub(/%22/, '"')
matches = `mdfind '#{query}' 2>/dev/null`.strip.split(/\n/)
res = matches.min_by { |r| File.basename(r).length }
return [false, query, link_text] if res.nil? || res.strip.empty?
title = File.basename(res)
link_text = title if link_text.strip.empty? || link_text == search_terms
["file://#{res.strip.gsub(/ /, '%20')}", title, link_text]
end
|