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



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

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



37
38
39
40
# File 'lib/searchlink/searches/hook.rb', line 37

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.



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

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



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

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