-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalfred.rb
66 lines (53 loc) · 1.46 KB
/
alfred.rb
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
59
60
61
62
63
64
65
66
require 'rubygems'
require 'plist'
require 'fileutils'
class AlfredInit
attr_reader :query
def initialize(query)
@query = query
if bundle_id
init_dir(temp_storage_path)
init_dir(storage_path)
end
end
def plist_path
File.join(File.dirname(__FILE__), 'info.plist')
end
def plist
@plist ||= Plist::parse_xml(plist_path)
end
def settings_path
File.join(storage_path, 'settings.plist')
end
def settings
@settings ||= Plist::parse_xml(settings_path) || {}
end
def store_settings!
File.open(settings_path, 'w') { |f| f.puts settings.to_plist }
end
# The plist bundleid as set by the workflow UI. Returns nil if not set.
def bundle_id
plist['bundleid'] if plist['bundleid'] != ''
end
# Volatile storage directory for this bundle
def temp_storage_path
assert_path_environment
"#{ENV['HOME']}/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/#{bundle_id}"
end
# Non-volatile storage directory for this bundle
def storage_path
assert_path_environment
"#{ENV['HOME']}/Library/Application Support/Alfred 2/Workflow Data/#{bundle_id}"
end
# Make sure bundle_id and ENV['HOME'] have reasonable values
def assert_path_environment
raise "Workflow has no bundle id set" unless bundle_id
raise "HOME directory is unknown" unless ENV['HOME'] and ENV['HOME'].size > 1
end
def init_dir(path)
FileUtils.mkdir_p(path)
end
def log(msg)
console_log(msg)
end
end