Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created April 2, 2011 13:40
Show Gist options
  • Save ttscoff/899503 to your computer and use it in GitHub Desktop.
Save ttscoff/899503 to your computer and use it in GitHub Desktop.
Returns the best running editor on a Mac, if any, based on my personal order of preference.
#!/usr/bin/ruby
#
# Returns the best running editor (Mac), if any, based on my personal order of preference.
def pick_editor
editors = ['TextMate','MacVim','Espresso','Coda','TextEdit']
ps = %x{ps Ao comm|grep .app|awk '{match($0,/([^\\/]+).app/); print substr($0,RSTART,RLENGTH)}'}.split("\n")
editors.each {|editor|
return editor if ps.include?(editor+".app")
}
return false
end
puts pick_editor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment