diff --git a/Blackspace.xcodeproj/project.pbxproj b/Blackspace.xcodeproj/project.pbxproj index 9895ead..563890c 100644 --- a/Blackspace.xcodeproj/project.pbxproj +++ b/Blackspace.xcodeproj/project.pbxproj @@ -92,6 +92,7 @@ TargetAttributes = { CE4238631BCC37C100B1AFBD = { CreatedOnToolsVersion = 7.0.1; + LastSwiftMigration = 0830; }; }; }; @@ -238,6 +239,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.peterpistorius.Blackspace; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -250,6 +252,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.peterpistorius.Blackspace; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Blackspace/AppDelegate.swift b/Blackspace/AppDelegate.swift index 4e949e8..67ff815 100644 --- a/Blackspace/AppDelegate.swift +++ b/Blackspace/AppDelegate.swift @@ -13,11 +13,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { - func applicationDidFinishLaunching(aNotification: NSNotification) { + func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application } - func applicationWillTerminate(aNotification: NSNotification) { + func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } diff --git a/Blackspace/Base.lproj/Main.storyboard b/Blackspace/Base.lproj/Main.storyboard old mode 100644 new mode 100755 index e3f7b96..5d44d9d --- a/Blackspace/Base.lproj/Main.storyboard +++ b/Blackspace/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - - + + - - + + @@ -642,7 +642,7 @@ - + @@ -668,14 +668,14 @@ - + - + - + I opened my eyes to only see the void. @@ -689,18 +689,28 @@ Poetry. + - diff --git a/Blackspace/Info.plist b/Blackspace/Info.plist index 1dff5aa..c8775c3 100644 --- a/Blackspace/Info.plist +++ b/Blackspace/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 1.1 CFBundleSignature ???? CFBundleVersion - 20151012 + 20170715 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/Blackspace/ViewController.swift b/Blackspace/ViewController.swift old mode 100644 new mode 100755 index d2be539..5b08138 --- a/Blackspace/ViewController.swift +++ b/Blackspace/ViewController.swift @@ -4,25 +4,48 @@ // // Created by Peter Pistorius on 12/10/15. // Copyright © 2015 Peter Pistorius. All rights reserved. -// (I don't care.) +// Updated by Perceval Faramaz on 15/07/17. +// Portions copyright © 2017 Perceval Faramaz. All rights reserved. +// (Me neither.) // import Cocoa class ViewController: NSViewController { - - func executeCommandLineTask(path: String, arguments: Array) { + + func buildTileDictionary(_ small: Bool) -> Dictionary { + var dict = Dictionary() + dict["tile-type"] = (small) ? "small-spacer-tile" : "spacer-tile" + return dict + } + + func reloadDock() { + let runningApplications = NSWorkspace.shared().runningApplications + for app in runningApplications { + if app.bundleIdentifier == "com.apple.dock" { + kill( app.processIdentifier, SIGKILL ); + } + } + } + + func insertSpacer(_ small: Bool) { + let dockDefaults = UserDefaults(suiteName: "com.apple.dock") + + guard var dockArray = dockDefaults?.array(forKey: "persistent-apps") else { return } - let task = NSTask() - task.launchPath = path - task.arguments = arguments - task.launch() - task.waitUntilExit() + dockArray.append( buildTileDictionary(small) ) + + dockDefaults!.set(dockArray, forKey: "persistent-apps") + + reloadDock() } - @IBAction func didClickInsertVoid(sender: AnyObject) { - executeCommandLineTask("/usr/bin/defaults", arguments: ["write", "com.apple.dock", "persistent-apps", "-array-add", "{\"tile-type\"=\"spacer-tile\";}"]); - executeCommandLineTask("/usr/bin/killall", arguments: ["Dock"]); + @IBAction func didClickInsertVoid(_ sender: AnyObject) { + insertSpacer(false) + } + + @IBAction func didClickInsertSmallVoid(_ sender: AnyObject) { + insertSpacer(true) } } diff --git a/README.md b/README.md index 8543047..1ce9b91 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,27 @@ ### Blackspace -Blackspace is an application that adds "blank" spaces to the OS X dock. +Blackspace is an application that adds "blank" spaces (or "spacers") to the macOS Dock. -![](https://github.com/peterp/Blackspace/blob/master/dock_example.png) +![](https://github.com/perfaram/Blackspace/blob/master/dock_example.png) This is most commonly used as a way to seperate apps into logical categories. To remove a space drag it off the Dock, like you would any other icon. -#### [Download](https://github.com/peterp/Blackspace/releases/download/1.0/Blackspace.app.zip) +#### [Download](https://github.com/perfaram/Blackspace/releases/download/1.1/Blackspace.zip) -[Download Blackspace.app](https://github.com/peterp/Blackspace/releases/download/1.0/Blackspace.app.zip) +[Download Blackspace.app](https://github.com/perfaram/Blackspace/releases/download/1.1/Blackspace.zip) #### How does it work? -It uses the following commands to achieve this, so if you're comfortable with using the Terminal then just do the following instead: +It uses a programmatic equivalent to the following commands to add Dock spacers, so if you're comfortable with using the Terminal then just do the following instead: ``` > defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}' > killall Dock ``` +Or, if you want a thin spacer, replaces `spacer-tile` by `small-spacer-tile`. + Enjoy.