alfred-workflow 1.11.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Gemfile.lock +45 -28
- data/Guardfile +4 -4
- data/History.txt +142 -0
- data/Manifest.txt +7 -0
- data/README.md +19 -1
- data/Rakefile +6 -4
- data/alfred-workflow.gemspec +27 -9
- data/lib/alfred.rb +275 -47
- data/lib/alfred/feedback.rb +112 -24
- data/lib/alfred/feedback/file_item.rb +2 -6
- data/lib/alfred/feedback/item.rb +10 -0
- data/lib/alfred/feedback/webloc_item.rb +1 -1
- data/lib/alfred/handler.rb +133 -0
- data/lib/alfred/handler/autocomplete.rb +86 -0
- data/lib/alfred/handler/callback.rb +130 -0
- data/lib/alfred/handler/cofig.rb +33 -0
- data/lib/alfred/handler/help.rb +162 -0
- data/lib/alfred/osx.rb +63 -0
- data/lib/alfred/setting.rb +29 -73
- data/lib/alfred/ui.rb +1 -0
- data/lib/alfred/util.rb +53 -5
- data/lib/alfred/version.rb +1 -1
- data/spec/alfred/feedback_spec.rb +8 -8
- data/spec/alfred/setting_spec.rb +44 -50
- data/spec/alfred_spec.rb +2 -10
- data/test/workflow/setting.yaml +2 -1
- metadata +304 -135
- metadata.gz.sig +1 -3
data/lib/alfred/osx.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Alfred
|
2
|
+
module OSX
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def version
|
7
|
+
@version ||= get_osx_version
|
8
|
+
end
|
9
|
+
|
10
|
+
def version_number
|
11
|
+
"#{version[:major]}.#{version[:minor]}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def notification_center?
|
15
|
+
version[:major] >= 10.8
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def full_name
|
20
|
+
"Mac OS X " + version_number
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def short_name
|
25
|
+
case version[:major]
|
26
|
+
when 10.4
|
27
|
+
short_name = "Tiger"
|
28
|
+
when 10.5
|
29
|
+
short_name = "Leopard"
|
30
|
+
when 10.6
|
31
|
+
short_name = "Snow Leopard"
|
32
|
+
when 10.7
|
33
|
+
short_name = "Lion"
|
34
|
+
when 10.8
|
35
|
+
short_name = "Mountain Lion"
|
36
|
+
when 10.9
|
37
|
+
short_name = "Mavericks"
|
38
|
+
end
|
39
|
+
|
40
|
+
return short_name
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def get_osx_version
|
47
|
+
begin
|
48
|
+
version = %x{/usr/bin/sw_vers -productVersion}.chop
|
49
|
+
rescue Errno::ENOENT => e
|
50
|
+
raise Errno::ENOENT, "This computer is not running Mac OS X becasue #{e.message}"
|
51
|
+
end
|
52
|
+
|
53
|
+
segments = version.split('.')[0,3].map!{|p| p.to_i}
|
54
|
+
{
|
55
|
+
:major => "#{segments[0]}.#{segments[1]}".to_f,
|
56
|
+
:minor => segments[2],
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
data/lib/alfred/setting.rb
CHANGED
@@ -1,101 +1,57 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
require 'plist'
|
3
2
|
|
4
3
|
module Alfred
|
5
4
|
|
6
|
-
class Setting
|
7
|
-
attr_accessor :
|
5
|
+
class Setting < ::Hash
|
6
|
+
attr_accessor :backend_file
|
7
|
+
attr_reader :format
|
8
8
|
|
9
|
-
def initialize(alfred, &
|
9
|
+
def initialize(alfred, &block)
|
10
|
+
super()
|
10
11
|
@core = alfred
|
11
|
-
instance_eval(&blk) if block_given?
|
12
|
-
raise InvalidFormat, "#{format} is not suported." unless validate_format
|
13
|
-
@backend = get_format_class(format).new(@core, setting_file)
|
14
|
-
end
|
15
|
-
|
16
|
-
def use_setting_file(opts = {})
|
17
|
-
@setting_file = opts[:file] if opts[:file]
|
18
|
-
@format = opts[:format] ? opts[:format] : "yaml"
|
19
|
-
end
|
20
12
|
|
13
|
+
instance_eval(&block) if block_given?
|
21
14
|
|
22
|
-
def validate_format
|
23
|
-
['yaml', 'plist'].include?(format)
|
24
|
-
end
|
25
|
-
|
26
|
-
def format
|
27
15
|
@format ||= "yaml"
|
28
|
-
|
16
|
+
@backend_file ||= File.join(@core.storage_path, "setting.#{@format}")
|
17
|
+
|
18
|
+
raise InvalidFormat, "#{format} is not suported." unless validate_format
|
29
19
|
|
30
|
-
|
31
|
-
|
20
|
+
unless File.exist?(@backend_file)
|
21
|
+
self.merge!({:id => @core.bundle_id})
|
22
|
+
dump(:flush => true)
|
23
|
+
else
|
24
|
+
load
|
25
|
+
end
|
32
26
|
end
|
33
27
|
|
34
|
-
def
|
35
|
-
|
28
|
+
def validate_format
|
29
|
+
['yaml'].include?(format)
|
36
30
|
end
|
37
31
|
|
38
32
|
def load
|
39
|
-
|
33
|
+
send("load_from_#{format}".to_sym)
|
40
34
|
end
|
41
35
|
|
42
|
-
def dump(
|
43
|
-
|
36
|
+
def dump(opts = {})
|
37
|
+
send("dump_to_#{format}".to_sym, opts)
|
44
38
|
end
|
45
39
|
|
46
|
-
|
47
|
-
attr_reader :setting_file
|
48
|
-
def initialize(alfred, file)
|
49
|
-
@core = alfred
|
50
|
-
@setting_file = file
|
51
|
-
end
|
40
|
+
alias_method :close, :dump
|
52
41
|
|
53
|
-
|
54
|
-
unless File.exist?(setting_file)
|
55
|
-
@settings = {:id => @core.bundle_id}
|
56
|
-
dump
|
57
|
-
end
|
42
|
+
protected
|
58
43
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
def dump(settings = nil, opts = {})
|
63
|
-
settings = @settings unless settings
|
64
|
-
|
65
|
-
File.open(setting_file, "wb") { |f|
|
66
|
-
YAML::dump(settings, f)
|
67
|
-
f.flush if opts[:flush]
|
68
|
-
}
|
69
|
-
end
|
44
|
+
def load_from_yaml
|
45
|
+
self.merge!(YAML::load_file(@backend_file))
|
70
46
|
end
|
71
47
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
def load
|
80
|
-
unless File.exist?(setting_file)
|
81
|
-
@settings = {:id => @core.bundle_id}
|
82
|
-
dump
|
83
|
-
end
|
84
|
-
|
85
|
-
@settings = Plist::parse_xml( File.read(setting_file) )
|
86
|
-
end
|
87
|
-
|
88
|
-
def dump(settings = nil, opts = {})
|
89
|
-
settings = @settings unless settings
|
90
|
-
|
91
|
-
File.open(setting_file, "wb") { |f|
|
92
|
-
f.puts settings.to_plist
|
93
|
-
f.flush if opts[:flush]
|
94
|
-
}
|
95
|
-
end
|
48
|
+
def dump_to_yaml(opts = {})
|
49
|
+
File.open(@backend_file, File::WRONLY|File::TRUNC|File::CREAT) { |f|
|
50
|
+
YAML::dump(self, f)
|
51
|
+
f.flush if opts[:flush]
|
52
|
+
}
|
96
53
|
end
|
97
54
|
|
98
|
-
|
99
55
|
end
|
100
56
|
end
|
101
57
|
|
data/lib/alfred/ui.rb
CHANGED
data/lib/alfred/util.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'terminal-notifier'
|
3
|
+
require 'alfred/osx'
|
4
|
+
|
1
5
|
class String
|
2
6
|
def strip_heredoc
|
3
7
|
indent = scan(/^[ \t]*(?=\S)/).min.size || 0
|
@@ -18,23 +22,67 @@ module Alfred
|
|
18
22
|
def make_webloc(name, url, folder=nil, comment = '')
|
19
23
|
date = Time.now.strftime("%m-%d-%Y %I:%M%p")
|
20
24
|
folder = Alfred.workflow_folder unless folder
|
21
|
-
folder, name, url, comment = [folder, name, url, comment].map do |t|
|
25
|
+
folder, name, url, comment = [folder, name, url, comment].map do |t|
|
22
26
|
escape_applescript(t)
|
23
27
|
end
|
24
28
|
|
25
29
|
return %x{
|
26
30
|
osascript << __APPLESCRIPT__
|
27
31
|
tell application "Finder"
|
28
|
-
set webloc to make new internet location file at (POSIX file "#{folder}") ¬
|
29
|
-
to "#{url}" with properties ¬
|
32
|
+
set webloc to make new internet location file at (POSIX file "#{folder}") ¬
|
33
|
+
to "#{url}" with properties ¬
|
30
34
|
{name:"#{name}",creation date:(AppleScript's date "#{date}"), ¬
|
31
35
|
comment:"#{comment}"}
|
32
36
|
end tell
|
33
37
|
return POSIX path of (webloc as string)
|
34
|
-
|
38
|
+
__APPLESCRIPT__}
|
35
39
|
end
|
40
|
+
|
41
|
+
|
42
|
+
def open_url(url)
|
43
|
+
uri = URI.parse(url)
|
44
|
+
%x{open #{uri.to_s}}
|
45
|
+
end
|
46
|
+
|
47
|
+
def reveal_in_finder(path)
|
48
|
+
raise InvalidArgument, "#{path} does not exist." unless File.exist? path
|
49
|
+
%x{osascript <<__APPLESCRIPT__
|
50
|
+
tell application "Finder"
|
51
|
+
try
|
52
|
+
reveal POSIX file "#{path}"
|
53
|
+
activate
|
54
|
+
on error err_msg number err_num
|
55
|
+
return err_msg
|
56
|
+
end try
|
57
|
+
end tell
|
58
|
+
__APPLESCRIPT__}
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def search_command(query = '')
|
63
|
+
%Q{osascript <<__APPLESCRIPT__
|
64
|
+
tell application "Alfred 2"
|
65
|
+
search "#{escape_applescript(query)}"
|
66
|
+
end tell
|
67
|
+
__APPLESCRIPT__}
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def notify(query, message, opts = {})
|
72
|
+
if Alfred::OSX.notification_center?
|
73
|
+
notifier_options = {
|
74
|
+
:title => 'Alfred Notification' ,
|
75
|
+
:sound => 'default' ,
|
76
|
+
:execute => search_command(query) ,
|
77
|
+
}.merge!(opts)
|
78
|
+
p notifier_options
|
79
|
+
TerminalNotifier.notify(message, notifier_options)
|
80
|
+
else
|
81
|
+
system search_command(query)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
36
85
|
end
|
37
86
|
end
|
38
87
|
|
39
88
|
end
|
40
|
-
|
data/lib/alfred/version.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Feedback" do
|
|
6
6
|
setup_workflow
|
7
7
|
|
8
8
|
@alfred = Alfred::Core.new
|
9
|
-
@feedback = Alfred::Feedback.new
|
9
|
+
@feedback = Alfred::Feedback.new(@alfred)
|
10
10
|
|
11
11
|
@item_elements = %w{title subtitle icon}
|
12
12
|
@item_attributes = %w{uid arg autocomplete}
|
@@ -67,15 +67,16 @@ describe "Feedback" do
|
|
67
67
|
use_cache_file :expire => 10
|
68
68
|
end
|
69
69
|
fb = @alfred.feedback
|
70
|
-
fb.
|
70
|
+
fb.backend_file.should == File.join(@alfred.volatile_storage_path, "cached_feedback")
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should set correct cache file" do
|
74
|
-
|
75
|
-
|
74
|
+
alfred = Alfred::Core.new
|
75
|
+
alfred.with_cached_feedback do
|
76
|
+
use_cache_file :file => "new_cached_feedback"
|
76
77
|
end
|
77
|
-
fb =
|
78
|
-
fb.
|
78
|
+
fb = alfred.feedback
|
79
|
+
fb.backend_file.should == "new_cached_feedback"
|
79
80
|
end
|
80
81
|
|
81
82
|
context "With Valid Cached File" do
|
@@ -130,13 +131,12 @@ describe "Feedback" do
|
|
130
131
|
end
|
131
132
|
|
132
133
|
end
|
133
|
-
|
134
134
|
end
|
135
135
|
|
136
136
|
after :all do
|
137
137
|
@alfred.with_cached_feedback
|
138
138
|
fb = @alfred.feedback
|
139
|
-
|
139
|
+
Fil.unlink(fb.backend_file)
|
140
140
|
reset_workflow
|
141
141
|
end
|
142
142
|
|
data/spec/alfred/setting_spec.rb
CHANGED
@@ -1,69 +1,31 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe "Setting" do
|
3
|
+
describe "Setting with yaml as backend" do
|
4
4
|
before :all do
|
5
5
|
setup_workflow
|
6
6
|
@alfred = Alfred::Core.new
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should use yaml as defualt backend" do
|
10
|
-
@setting
|
11
|
-
@setting.format.should == "yaml"
|
10
|
+
@alfred.setting.format.should == "yaml"
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
@setting = @alfred.setting do
|
17
|
-
use_setting_file :format => 'yaml'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
it "should correctly load settings" do
|
21
|
-
settings = @setting.load
|
22
|
-
settings[:id].should == "me.zhaowu.alfred-workflow-gem"
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should correctly save settings" do
|
26
|
-
settings = @setting.load
|
27
|
-
settings[:language] = "Chinese"
|
28
|
-
@setting.dump(settings, :flush => true)
|
29
|
-
|
30
|
-
settings = @alfred.setting.load
|
31
|
-
settings[:language].should == "Chinese"
|
32
|
-
end
|
33
|
-
|
34
|
-
after :all do
|
35
|
-
File.unlink(@setting.setting_file)
|
36
|
-
end
|
13
|
+
it "should correctly load settings" do
|
14
|
+
@alfred.setting[:id].should == "me.zhaowu.alfred-workflow-gem"
|
37
15
|
end
|
38
16
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
it "should correctly load settings" do
|
47
|
-
settings = @setting.load
|
48
|
-
settings[:id].should == "me.zhaowu.alfred-workflow-gem"
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should correctly save settings" do
|
52
|
-
settings = @setting.load
|
53
|
-
settings[:language] = "Chinese"
|
54
|
-
@setting.dump(settings, :flush => true)
|
55
|
-
|
56
|
-
settings = @alfred.setting.load
|
57
|
-
settings[:language].should == "Chinese"
|
58
|
-
end
|
59
|
-
|
60
|
-
after :all do
|
61
|
-
File.unlink(@setting.setting_file)
|
62
|
-
end
|
17
|
+
it "should correctly save settings" do
|
18
|
+
@alfred.setting[:language] = "Chinese"
|
19
|
+
@alfred.setting.dump(:flush => true)
|
20
|
+
|
21
|
+
@alfred.setting.load
|
22
|
+
@alfred.setting[:language].should == "Chinese"
|
63
23
|
end
|
64
24
|
|
25
|
+
|
65
26
|
after :all do
|
66
27
|
reset_workflow
|
28
|
+
File.unlink(@alfred.setting.backend_file)
|
67
29
|
end
|
68
30
|
|
69
31
|
end
|
@@ -71,4 +33,36 @@ end
|
|
71
33
|
|
72
34
|
|
73
35
|
|
36
|
+
# describe "Setting with plist as backend" do
|
37
|
+
# before :all do
|
38
|
+
# setup_workflow
|
39
|
+
# @alfred = Alfred::Core.new
|
40
|
+
|
41
|
+
# @alfred.setting do
|
42
|
+
# @format = 'plist'
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
|
46
|
+
# it "should correctly load settings" do
|
47
|
+
# @alfred.setting['id'].should == "me.zhaowu.alfred-workflow-gem"
|
48
|
+
# end
|
49
|
+
|
50
|
+
# it "should correctly save settings" do
|
51
|
+
# @alfred.setting['language'] = "English"
|
52
|
+
# @alfred.setting.dump(:flush => true)
|
53
|
+
|
54
|
+
# @alfred.setting['language'].should == "English"
|
55
|
+
# end
|
56
|
+
|
57
|
+
|
58
|
+
# after :all do
|
59
|
+
# reset_workflow
|
60
|
+
# File.unlink(@alfred.setting.backend_file)
|
61
|
+
# end
|
62
|
+
|
63
|
+
# end
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
74
68
|
|