forked from ngreenstein/alfred-process-killer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.plist
266 lines (256 loc) · 9.22 KB
/
info.plist
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>bundleid</key>
<string>com.lucasarts.alfred-restart-app</string>
<key>connections</key>
<dict>
<key>2A751056-87B7-4408-90D6-B868021760CE</key>
<array>
<dict>
<key>destinationuid</key>
<string>31AD6783-08D4-48E0-B323-39292BF089D6</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>C4986824-5761-4F2E-A82F-E4EBC2CAF54C</string>
<key>modifiers</key>
<integer>1048576</integer>
<key>modifiersubtext</key>
<string>Kill all processes with this name.</string>
<key>vitoclose</key>
<false/>
</dict>
</array>
</dict>
<key>createdby</key>
<string>lūcēte celsē</string>
<key>description</key>
<string>Easily find and kill misbehaving app/processes.</string>
<key>disabled</key>
<false/>
<key>name</key>
<string>Restart App/Process</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>0</integer>
<key>script</key>
<string>#kill -9 {query}
tell application "{query}" quitend telldelay 1 -- Wait for app "qeury" to closetell application "{query}" to activate</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>6</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>31AD6783-08D4-48E0-B323-39292BF089D6</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false/>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>0</integer>
<key>keyword</key>
<string>restart</string>
<key>queuedelaycustom</key>
<integer>1</integer>
<key>queuedelayimmediatelyinitially</key>
<false/>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>1</integer>
<key>runningsubtext</key>
<string>Finding processes...</string>
<key>script</key>
<string># Type a query to test with here.
# !!!!! Comment this line out when pasting into alfred preferences.
#theQuery = "chr"
# Grab the query that the user typed (this is provided by Alfred).
# !!!!! Uncomment this line when pasting into Alfred Preferences.
theQuery = "{query}"
# Search the query string for an argument filter (in the form of 'process:arg').
argsQuery = nil
if theQuery.include? ":"
theQuery, argsQuery = theQuery.split(":")
end
# Assemble an array of each matching process. It will contain the process's path and percent CPU usage.
# The -A flag shows all processes. The -o pid, -o %cpu, and -o comm show only the process's PID, CPU usage and path, respectively.
# Grep for processes whose name contains the query. The regex isolates the name by only searching characters after the last slash in the path.
# The -i flag ignores case.
processes = `ps -A -o pid -o %cpu -o comm | grep -i [^/]*#{Regexp.quote(theQuery)}[^/]*$`.split("\n")
# Start the XML string that will be sent to Alfred. This just uses strings to avoid dependencies.
xmlString = "<?xml version=\"1.0\"?>\n<items>\n"
processes.each do | process |
# Extract the PID, CPU usage, and path from the line (lines are in the form of `123 12.3 /path/to/process`).
processId, processCpu, processPath = process.match(/(\d+)\s+(\d+[\.|\,]\d+)\s+(.*)/).captures
# If an argument filter has been specified, get the arguments and search for the filter.
matchedArgs = []
if argsQuery != nil
# Get the executable path and arguments for this process. Make an array with each argument that matches the search.
matchedArgs = `ps -p #{processId} -o command`.scan(/\s+-{1,2}[^\s]*#{Regexp.quote(argsQuery)}[^\s]*/i)
if matchedArgs.length < 1
next
end
end
# Use the same expression as before to isolate the name of the process.
processName = processPath.match(/[^\/]*#{theQuery}[^\/]*$/i)
# Search for an application bundle in the path to the process.
iconValue = processPath.match(/.*?\.app\//)
# The icon type sent to Alfred is 'fileicon' (taken from a file). This assumes that a .app was found.
iconType = "fileicon"
# If no .app was found, use OS X's generic 'executable binary' icon.
# An empty icon type tells Alfred to load the icon from the file itself, rather than loading the file type's icon.
if !iconValue
iconValue = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ExecutableBinaryIcon.icns"
iconType = ""
end
# Assemble this item's XML string for Alfred. See http://www.alfredforum.com/topic/5-generating-feedback-in-workflows/
# thisXmlString = "\t<item uid=\"#{processName}\" arg=\"#{processId}\">
thisXmlString = "\t<item uid=\"#{processName}\" arg=\"#{processName}\">
<title>#{processName}#{matchedArgs.join(" ")}</title>
<subtitle>#{processCpu}% CPU @ #{processPath}</subtitle>
<icon type=\"#{iconType}\">#{iconValue}</icon>
</item>\n"
# Append this process's XML string to the global XML string.
xmlString += thisXmlString
end
# Finish off and echo the XML string to Alfred.
xmlString += "</items>"
puts xmlString</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Start typing a process name...</string>
<key>title</key>
<string>Restart Process Named</string>
<key>type</key>
<integer>2</integer>
<key>withspace</key>
<true/>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>2A751056-87B7-4408-90D6-B868021760CE</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>0</integer>
<key>script</key>
<string>killall -- "$(ps -c -p {query} -o comm | tail -n 1)"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>C4986824-5761-4F2E-A82F-E4EBC2CAF54C</string>
<key>version</key>
<integer>2</integer>
</dict>
</array>
<key>readme</key>
<string>#Description
Kill Process is an Alfred 2 workflow that makes it easy to kill misbehaving processes. It is, in essence, a way to easily find processes by name and kill them using `kill -9`.
#Features
* Autocompletes process names
* Learns and prioritizes processes you kill frequently
* Shows icons when possible
* Shows CPU usage
* Shows process paths
* Ignores case
* Kills all processes with matching names on <kbd>cmd</kbd>+<kbd>return</kbd>
* Supports [Alleyoop updating](http://www.alfredforum.com/topic/1582-alleyoop-update-alfred-workflows/).
![screenshot: `kill it`](screenshot.png)
#Usage
1. Type `kill` into Alfred followed by a space.
2. Begin typing the name of the process you want to kill.
3. When you see the process you want to kill, select it from the list as usual.
4. Press return to kill the selected process.
Alternatively, press <kbd>cmd</kbd>+<kbd>return</kbd> to kill all processes with the same name as the selected one.
#Installation
Open `Kill Process.alfredworkflow` and Alfred will walk you through the installation process. No configuration is necessary.
#Making Changes
##Editing the Script
The ruby script that powers Kill Process is `script.rb`. For testing, add a value for `theQuery` in the first line. Be sure that the subsequent `theQuery = "{query}"` is commented out. This allows you to hard-code a search query instead of taking what the user has typed from Alfred. See the comments in the script for more info.
##Applying Changes to the Workflow
1. Be sure that the first line in the script setting `theQuery` is commented out and that the second line (`theQuery = "{query}"`) is not commented out.
2. Open the Workflows tab of Alfred's Preferences.
3. Select the Kill Process workflow on the left.
4. Double click the first box ('kill Script Filter').
5. Paste your script into the 'Script' box at the bottom.
6. Click Save.
#License
[WTFPL](http://www.wtfpl.net/about/), of course.</string>
<key>uidata</key>
<dict>
<key>2A751056-87B7-4408-90D6-B868021760CE</key>
<dict>
<key>xpos</key>
<integer>280</integer>
<key>ypos</key>
<integer>170</integer>
</dict>
<key>31AD6783-08D4-48E0-B323-39292BF089D6</key>
<dict>
<key>xpos</key>
<integer>500</integer>
<key>ypos</key>
<real>170</real>
</dict>
<key>C4986824-5761-4F2E-A82F-E4EBC2CAF54C</key>
<dict>
<key>xpos</key>
<integer>500</integer>
<key>ypos</key>
<real>340</real>
</dict>
</dict>
<key>webaddress</key>
<string>https://github.com/luceat-lux-vestra/alfred-restart-app</string>
</dict>
</plist>