Class: SL::HookSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/searchlink/searches/hook.rb

Overview

Hookmark Search

Class Method Summary collapse

Class Method Details

.run_query(query) ⇒ Object

Run the AppleScript Hookmark query

Parameters:

  • query (String)

    The query



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/searchlink/searches/hook.rb', line 45

def run_query(query)
  `osascript <<'APPLESCRIPT'
    tell application "Hook"
      set _marks to every bookmark whose #{query}
      set _out to {}
      repeat with _hook in _marks
        set _out to _out & (name of _hook & "||" & address of _hook & "||" & path of _hook)
      end repeat
      set {astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "^^"}
      set _output to _out as string
      set AppleScript's text item delimiters to astid
      return _output
    end tell
  APPLESCRIPT`.strip.split_hooks
end

.search(_, search_terms, link_text) ⇒ Object

Main search method



35
36
37
38
# File 'lib/searchlink/searches/hook.rb', line 35

def search(_, search_terms, link_text)
  url, title = search_hook(search_terms)
  [url, title, link_text]
end

.search_hook(search) ⇒ Object

Search bookmark paths and addresses. Return array of bookmark hashes.



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/searchlink/searches/hook.rb', line 62

def search_hook(search)
  types = %w[name path address]
  query = search.strip.split(' ').map { |s| types.map { |t| %(#{t} contains "#{s}") }.join(' or ') }
  query = query.map { |q| "(#{q})" }.join(' and ')
  path_matches = run_query(query)

  top_match = path_matches.uniq.first
  return false unless top_match

  [top_match[:url], top_match[:name]]
end

.settingsObject



25
26
27
28
29
30
31
32
# File 'lib/searchlink/searches/hook.rb', line 25

def settings
  {
    trigger: 'hook',
    searches: [
      ['hook', 'Hookmark Bookmark Search']
    ]
  }
end