class MacShortcuts::ApplicationPreferencesFinder
Public Class Methods
find_with_query(query)
click to toggle source
@param [String] query
@return [Array<String>] paths to preferences file
# 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
Private Class Methods
bundle_identifier_of(app_path)
click to toggle source
@param [String] app_path path to application folder, example: ‘/Applications/Messages.app’
@return [String, nil] bundle identifier of that application
# File lib/mac_shortcuts/application_preferences_finder.rb, line 71 def self.bundle_identifier_of(app_path) plist_path = "#{app_path}/Contents/Info.plist" `/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "#{plist_path}"`.chomp end
preferences_path()
click to toggle source
@return [String] base path for user application preferences
# File lib/mac_shortcuts/application_preferences_finder.rb, line 45 def self.preferences_path @preferences_path ||= File.join(Dir.home, 'Library', 'Preferences') end
preferences_path_of(app_path)
click to toggle source
@param [String] app_path path to application folder
@return [String] preference path of input application
# File lib/mac_shortcuts/application_preferences_finder.rb, line 63 def self.preferences_path_of(app_path) File.join(preferences_path, "#{self.bundle_identifier_of(app_path)}.plist") end
process_apps_paths(apps_paths)
click to toggle source
@param [Array<String>] apps_paths paths to applications folder
@return [Array<String>] preference paths of input applications
# File lib/mac_shortcuts/application_preferences_finder.rb, line 53 def self.process_apps_paths(apps_paths) apps_paths.map do |app_path| preferences_path_of(app_path) end end