Class: SL::SpotlightSearch
- Inherits:
-
Object
- Object
- SL::SpotlightSearch
- Defined in:
- lib/searchlink/searches/spotlight.rb
Overview
Spotlight file search
Class Method Summary collapse
Class Method Details
.search(_, search_terms, link_text) ⇒ Object
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.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 |
.settings ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/searchlink/searches/spotlight.rb', line 7 def settings { trigger: 'file', searches: [ ['file', 'Spotlight Search'] ] } end |