Skip to content

Instantly share code, notes, and snippets.

@hryk
Last active December 12, 2015 00:08
Show Gist options
  • Save hryk/4681703 to your computer and use it in GitHub Desktop.
Save hryk/4681703 to your computer and use it in GitHub Desktop.
Terminate and re-launch an application with MacRuby.
#!/usr/bin/env ruby
#encoding: utf-8
framework 'Cocoa'
framework 'ApplicationServices'
framework 'AppKit'
# Get a list of applications currently running.
ws = NSWorkspace.sharedWorkspace
apps = ws.runningApplications
applist = {}
apps.each do |app|
applist[app.localizedName] = app.executableURL.path.lastPathComponent
# Terminate 夜フクロウ
if app.localizedName == "夜フクロウ"
app.terminate
end
end
sleep 5
# Re-launch 夜フクロウ
ws.launchApplication(applist["夜フクロウ"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment