Skip to content

Commit 20982f1

Browse files
initial commit
0 parents  commit 20982f1

File tree

9 files changed

+7529
-0
lines changed

9 files changed

+7529
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Mac OSX Finder caches
2+
.DS_Store
3+
4+
# Downloaded caches
5+
Caches

Library/workflow.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require 'net/http'
2+
require 'net/https'
3+
require 'json'
4+
5+
6+
HOST = "http://raw.githubusercontent.com"
7+
WORKFLOW_PATH = "~/Library/Application\\ Support/Alfred\\ 2/Alfred.alfredpreferences/workflows"
8+
FILE_CACHE = "workflow_api.json"
9+
CACHES_DIRECTORY = "./Caches"
10+
11+
module Workflow
12+
require "./Library/workflow/list"
13+
require "./Library/workflow/remote"
14+
require "./Library/workflow/curl"
15+
16+
def self.index
17+
workflows = Workflow::Remote.index()
18+
puts Workflow::List.generate_xml(workflows)
19+
end
20+
21+
def self.search
22+
query = ARGV[1]
23+
if query && query != ""
24+
workflows = Workflow::Remote.search(query)
25+
puts Workflow::List.generate_xml(workflows)
26+
else
27+
self.index()
28+
end
29+
end
30+
31+
def self.download
32+
id = ARGV[1]
33+
workflow = Workflow::Remote.get(id)
34+
workflow_download_link = workflow["workflow_download_link"]
35+
workflow_file = workflow["workflow_file"]
36+
Workflow::Curl.download(workflow_download_link, workflow_file)
37+
end
38+
end
39+
40+
########################## Script goes here
41+
case ARGV[0]
42+
when "index"
43+
if ARGV[1].nil?
44+
Workflow.index
45+
else
46+
Workflow.search
47+
end
48+
49+
when "download"
50+
Workflow.download
51+
end

Library/workflow/curl.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'open-uri'
2+
3+
module Workflow
4+
class Curl
5+
def self.download(workflow_download_link, workflow_file)
6+
# create a temp file
7+
src = open(workflow_download_link)
8+
puts workflow_download_link
9+
type = src.content_type
10+
11+
if type == "application/zip"
12+
filepath = '#{CACHES_DIRECTORY}/tmp.zip'
13+
else
14+
filepath = "#{CACHES_DIRECTORY}/#{workflow_file}"
15+
end
16+
17+
open(filepath, 'wb') do |file|
18+
file << src.read
19+
end
20+
21+
src.close()
22+
src.unlink()
23+
24+
filename = File.basename(filepath, File.extname(filepath))
25+
if type == 'application/zip'
26+
# extract zip file
27+
puts `cd #{CACHES_DIRECTORY} && unzip tmp.zip && rm tmp.zip`
28+
end
29+
puts `cd #{CACHES_DIRECTORY} && unzip #{workflow_file} -d #{WORKFLOW_PATH}/#{filename}`
30+
end
31+
end
32+
end

Library/workflow/list.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Workflow
2+
class List
3+
def self.generate_xml(workflows)
4+
xml = []
5+
xml << "<?xml version='1.0'?><items>"
6+
7+
if workflows.empty?
8+
xml << """
9+
<item valid='no'>
10+
<title>No results</title>
11+
</item>"""
12+
else
13+
workflows.each do |workflow|
14+
xml << """
15+
<item uid='#{workflow["workflow_name"]}' arg='#{workflow["workflow_download_link"]}'>
16+
<title>#{workflow["workflow_name"]}</title>
17+
<subtitle>#{workflow["workflow_description_small"]}</subtitle>
18+
<icon>icon.png</icon>
19+
</item>"""
20+
end
21+
end
22+
23+
xml << "</items>"
24+
xml.join
25+
end
26+
end
27+
end

Library/workflow/remote.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module Workflow
2+
class Remote
3+
@@workflows = JSON.parse(IO.read("#{FILE_CACHE}"))
4+
5+
def self.index(query = nil)
6+
return @@workflows
7+
end
8+
9+
def self.get(id)
10+
@@workflows.each do |workflow|
11+
if workflow["workflow_download_link"] == id
12+
return workflow
13+
end
14+
end
15+
end
16+
17+
def self.search(query)
18+
ret = Array.new
19+
@@workflows.each do |workflow|
20+
haystack = workflow["workflow_name"]
21+
if !haystack.downcase.include?(query.downcase)
22+
else
23+
ret.push workflow
24+
end
25+
end
26+
return ret
27+
end
28+
end
29+
end

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Workflow Manager for Alfred
2+
3+
4+
## Usage
5+
6+
Type `af {query}` to search workflows and then select the workflow you want and hit `enter`. Done!
7+
8+
9+
## Thanks to...
10+
11+
* [Adam Butler](https://github.com/adambutler) and his [alfred-workflow-package-manager-workflow repository](https://github.com/adambutler/alfred-workflow-package-manager-workflow)
12+
* [hzlzh](https://github.com/hzlzh) and his [`workflow_api.json`](workflow_api.json)

icon.png

67.8 KB
Loading

info.plist

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>bundleid</key>
6+
<string>com.will.workflow</string>
7+
<key>category</key>
8+
<string>Tools</string>
9+
<key>connections</key>
10+
<dict>
11+
<key>7DD3BDE5-A157-42E5-9376-F681FB50A4EE</key>
12+
<array>
13+
<dict>
14+
<key>destinationuid</key>
15+
<string>06C9C4A9-38CE-441A-8D06-E2F2D8B39B60</string>
16+
<key>modifiers</key>
17+
<integer>0</integer>
18+
<key>modifiersubtext</key>
19+
<string></string>
20+
</dict>
21+
</array>
22+
</dict>
23+
<key>createdby</key>
24+
<string>Will</string>
25+
<key>description</key>
26+
<string>Workflow Manager for Alfred</string>
27+
<key>disabled</key>
28+
<false/>
29+
<key>name</key>
30+
<string>Workflow Manager</string>
31+
<key>objects</key>
32+
<array>
33+
<dict>
34+
<key>config</key>
35+
<dict>
36+
<key>argumenttype</key>
37+
<integer>1</integer>
38+
<key>escaping</key>
39+
<integer>127</integer>
40+
<key>keyword</key>
41+
<string>af</string>
42+
<key>queuedelaycustom</key>
43+
<integer>3</integer>
44+
<key>queuedelayimmediatelyinitially</key>
45+
<false/>
46+
<key>queuedelaymode</key>
47+
<integer>0</integer>
48+
<key>queuemode</key>
49+
<integer>1</integer>
50+
<key>runningsubtext</key>
51+
<string>Loading</string>
52+
<key>script</key>
53+
<string>ruby Library/workflow.rb index {query}</string>
54+
<key>title</key>
55+
<string>Search for Workflows</string>
56+
<key>type</key>
57+
<integer>0</integer>
58+
<key>withspace</key>
59+
<true/>
60+
</dict>
61+
<key>type</key>
62+
<string>alfred.workflow.input.scriptfilter</string>
63+
<key>uid</key>
64+
<string>7DD3BDE5-A157-42E5-9376-F681FB50A4EE</string>
65+
<key>version</key>
66+
<integer>0</integer>
67+
</dict>
68+
<dict>
69+
<key>config</key>
70+
<dict>
71+
<key>escaping</key>
72+
<integer>127</integer>
73+
<key>script</key>
74+
<string>ruby Library/workflow.rb download {query}</string>
75+
<key>type</key>
76+
<integer>0</integer>
77+
</dict>
78+
<key>type</key>
79+
<string>alfred.workflow.action.script</string>
80+
<key>uid</key>
81+
<string>06C9C4A9-38CE-441A-8D06-E2F2D8B39B60</string>
82+
<key>version</key>
83+
<integer>0</integer>
84+
</dict>
85+
</array>
86+
<key>readme</key>
87+
<string></string>
88+
<key>uidata</key>
89+
<dict>
90+
<key>06C9C4A9-38CE-441A-8D06-E2F2D8B39B60</key>
91+
<dict>
92+
<key>ypos</key>
93+
<real>60</real>
94+
</dict>
95+
<key>7DD3BDE5-A157-42E5-9376-F681FB50A4EE</key>
96+
<dict>
97+
<key>ypos</key>
98+
<real>60</real>
99+
</dict>
100+
</dict>
101+
<key>webaddress</key>
102+
<string>https://github.com/githubutilities/alfred-workflow-manager</string>
103+
</dict>
104+
</plist>

0 commit comments

Comments
 (0)