Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created May 19, 2010 15:53
Show Gist options
  • Save cowboy/406459 to your computer and use it in GitHub Desktop.
Save cowboy/406459 to your computer and use it in GitHub Desktop.
Restart App AppleScript
(*
* Restart App - v1.0 - 5/19/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*)
-- Usage:
--
-- To quit and restart "FooBar.app" just save this AppleScript as an
-- Application Bundle named "Restart FooBar.app" and run it. Make as many
-- copies as you want, just change the name as needed. This is especially
-- useful for managing misbehaving background or menubar apps.
tell application "Finder"
set appName to name of file (path to me) as text
set appName to quoted form of appName
set appName to do shell script "echo " & appName & " | sed 's/Restart \\(.*\\)\\.app/\\1/'"
end tell
do shell script "kill $(ps -e -o pid,command | grep " & appName & " | sed -E 's/^ *([0-9]+).*$/\\1/;q'); exit 0"
do shell script "open -a " & appName & ".app"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment