From 948e243e24400e442f5962b13918116d8e67fdbb Mon Sep 17 00:00:00 2001 From: Perceval FARAMAZ Date: Sat, 15 Jul 2017 10:25:43 +0200 Subject: [PATCH 1/4] Don't use command line, make system calls instead ; can now add small spacers ; converted to Swift 3 syntax Signed-off-by: Perceval FARAMAZ --- Blackspace.xcodeproj/project.pbxproj | 3 ++ Blackspace/AppDelegate.swift | 4 +-- Blackspace/Base.lproj/Main.storyboard | 36 +++++++++++++-------- Blackspace/ViewController.swift | 45 ++++++++++++++++++++------- 4 files changed, 62 insertions(+), 26 deletions(-) mode change 100644 => 100755 Blackspace/Base.lproj/Main.storyboard mode change 100644 => 100755 Blackspace/ViewController.swift 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/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) } } From 0ef1e31e45ba6f626d0a814e342f67c3977146c6 Mon Sep 17 00:00:00 2001 From: Perceval Faramaz Date: Sat, 15 Jul 2017 10:46:51 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8543047..59e0c01 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.app.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.app.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. From 9ee713d078760098c08b627447bff3d615d82853 Mon Sep 17 00:00:00 2001 From: Perceval Faramaz Date: Sat, 15 Jul 2017 13:14:07 +0200 Subject: [PATCH 3/4] Linking to new release 1.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59e0c01..1ce9b91 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ 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/perfaram/Blackspace/releases/download/1.1/Blackspace.app.zip) +#### [Download](https://github.com/perfaram/Blackspace/releases/download/1.1/Blackspace.zip) -[Download Blackspace.app](https://github.com/perfaram/Blackspace/releases/download/1.1/Blackspace.app.zip) +[Download Blackspace.app](https://github.com/perfaram/Blackspace/releases/download/1.1/Blackspace.zip) #### How does it work? From a06ef966b258fb5ab0f57f50eed4a8a6f1118749 Mon Sep 17 00:00:00 2001 From: Perceval FARAMAZ Date: Sat, 15 Jul 2017 13:19:49 +0200 Subject: [PATCH 4/4] 1.1 Release build setting --- Blackspace/Info.plist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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