-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_searches
executable file
·58 lines (45 loc) · 1.67 KB
/
merge_searches
1
2
3
4
5
6
7
8
9
10
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env ruby -rubygems
begin
require 'plist'
rescue LoadError
puts "plist gem not found. Please run `gem install plist` and try again."
end
class String
def to_prefix
self.strip.downcase.gsub(/\W+/, '')
end
end
home_dir = %x(echo "$HOME")
home_dir.chomp!
LAUNCHBAR_PLIST_PATH = "#{home_dir}/Library/Application Support/LaunchBar/Configuration.plist"
ALFRED_PLIST_PATH = "#{home_dir}/Library/Application Support/Alfred/customsites/customsites.plist"
launchbar_plist = Plist::parse_xml LAUNCHBAR_PLIST_PATH
launchbar_searches = []
launchbar_plist['rules'].each do |rule|
launchbar_searches << rule if rule['className'] == "ODLBSearchTemplatesRule"
end
converted_searches = []
launchbar_searches.each_with_index do |search, index|
alias_matches = search['aliasName'].match(/(Custom )?Search Templates( \((.*)\))?/)
prefix = alias_matches[1] ? alias_matches[1].to_prefix : alias_matches[3].to_prefix
search['templates'].each do |template|
template_name = template['name'].to_prefix
template_url = template['templateURL'].sub('*', '{query}')
search = {
"keyword" => "#{template_name}",
"spaces" => false,
"text" => "#{template['name']} #{search['aliasName'].to_s.sub('Templates', 'Template')}".strip,
"url" => template_url,
"utf8" => alias_matches[3].to_s == 'UTF-8',
}
converted_searches << search
end
end
converted_searches.sort!{|x, y| x["keyword"] <=> y["keyword"] }
alfred_plist = Plist::parse_xml ALFRED_PLIST_PATH
alfred_plist = converted_searches + alfred_plist
puts alfred_plist.to_plist
# Potentially dangerous!
# File.open(ALFRED_PLIST_PATH, 'w+') do |file|
# file.puts alfred_plist.to_plist
# end