Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Kill Process.alfredworkflow
Binary file not shown.
6 changes: 3 additions & 3 deletions script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# 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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you think about using the dedicated GNU tool for that?

- awk 'NR>1'
+ sort -n +2

processes = `ps -A -o pid -o %cpu -o comm | awk 'NR>1' | sort -nrk 2,2 | 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 |
Expand Down Expand Up @@ -41,7 +41,7 @@
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 arg=\"#{processId}\">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this configurable.

Also don't remove the uid but instead conditionally use skipknowledge to show the most killed processes before that the user starts typing a process name.

<title>#{processName}#{matchedArgs.join(" ")}</title>
<subtitle>#{processCpu}% CPU @ #{processPath}</subtitle>
<icon type=\"#{iconType}\">#{iconValue}</icon>
Expand All @@ -51,4 +51,4 @@
end
# Finish off and echo the XML string to Alfred.
xmlString += "</items>"
puts xmlString
puts xmlString