Help us understand the problem. What is going on with this article?

Dock のアプリを必要なもの以外まとめて終了するスクリプト

More than 3 years have passed since last update.

Swift でスクリプトを書いてみた。

killdock.swift
#!/usr/bin/env swift

import Cocoa

// Dock に表示されるアプリケーションの一覧を取得
func getRegularApplications() -> [NSRunningApplication] {
    let runningApps = NSWorkspace.sharedWorkspace().runningApplications as! [NSRunningApplication]
    let regularApps = runningApps.filter { (app: NSRunningApplication) in
        app.activationPolicy == NSApplicationActivationPolicy.Regular
    }
    return regularApps
}

// ホワイトリストに含まれないアプリケーションをまとめて終了
func killApplications(apps: [NSRunningApplication]) {
    let allowed = getAllowedBundleIdentifiers()
    for app in apps {
        if contains(allowed, app.bundleIdentifier!) {
            println("Skipped \(app.localizedName!) (\(app.bundleIdentifier!))")
            continue
        }
        println("Killed  \(app.localizedName!) (\(app.bundleIdentifier!))")
        app.terminate()
    }
}

// 終了させないアプリケーションのホワイトリスト
// Finder 以外の項目はお好みで
func getAllowedBundleIdentifiers() -> [String] {
    return ["com.apple.finder",
            "com.omnigroup.OmniFocus2.MacAppStore",
            "com.apple.Safari"]
}

killApplications(getRegularApplications())
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away