Class: MacShortcuts::ApplicationPreferencesFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/mac_shortcuts/application_preferences_finder.rb

Class Method Summary collapse

Class Method Details

.find_with_query(query) ⇒ Array<String>

Returns paths to preferences file.

Parameters:

  • query (String)

Returns:

  • (Array<String>)

    paths to preferences file



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mac_shortcuts/application_preferences_finder.rb', line 11

def self.find_with_query(query)
  founded = Dir[File.join(preferences_path, "*.#{query}.plist")]
  return founded unless founded.empty?

  apps_dirs_paths = [
      '/Applications',
      File.join(Dir.home, 'Applications'),
  ]

  apps_dirs_paths.each do |apps_path|
    founded = process_apps_paths(Dir[File.join(apps_path, "#{query}.app")])
    return founded unless founded.empty?
  end

  return founded unless founded.empty?

  # use Spotlight to find applications
  apps_paths = `mdfind "#{query}.app"`.split("\n")

  # filter out not application results
  apps_paths.select! do |path|
    path.end_with?('.app')
  end

  founded = process_apps_paths(apps_paths)

  founded
end