├── .gitignore ├── EventMonitor.swift ├── LICENSE ├── MSC DND ├── AppDelegate.swift ├── Base.lproj │ └── MainMenu.xib ├── DNDViewController.swift ├── DNDViewController.xib ├── Images.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ └── hibernate@2x.png │ └── hibernate.imageset │ │ ├── Contents.json │ │ └── hibernate@2x.png ├── Info.plist └── hibernate@2x.png ├── MSC DNDTests ├── Info.plist └── MSC_DNDTests.swift ├── Makefile ├── Managed Software Center DND.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── README.md ├── images ├── active.png └── disabled.png └── munki-dnd.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | 35 | *.pkg 36 | -------------------------------------------------------------------------------- /EventMonitor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EventMonitor.swift 3 | // MSC DND 4 | // 5 | // Created by Graham Gilbert on 05/07/2015. 6 | // Copyright (c) 2015 Graham Gilbert. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | public class EventMonitor { 12 | private var monitor: AnyObject? 13 | private let mask: NSEventMask 14 | private let handler: NSEvent? -> () 15 | 16 | public init(mask: NSEventMask, handler: NSEvent? -> ()) { 17 | self.mask = mask 18 | self.handler = handler 19 | } 20 | 21 | deinit { 22 | stop() 23 | } 24 | 25 | public func start() { 26 | monitor = NSEvent.addGlobalMonitorForEventsMatchingMask(mask, handler: handler) 27 | } 28 | 29 | public func stop() { 30 | if monitor != nil { 31 | NSEvent.removeMonitor(monitor!) 32 | monitor = nil 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /MSC DND/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // MSC DND 4 | // 5 | // Created by Graham Gilbert on 05/07/2015. 6 | // Copyright (c) 2015 Graham Gilbert. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | @IBOutlet weak var window: NSWindow! 15 | let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-2) 16 | let popover = NSPopover() 17 | var eventMonitor: EventMonitor? 18 | 19 | func applicationDidFinishLaunching(notification: NSNotification) { 20 | 21 | if let button = statusItem.button { 22 | button.image = NSImage(named: "hibernate") 23 | button.action = Selector("togglePopover:") 24 | } 25 | 26 | popover.contentViewController = DNDViewController(nibName: "DNDViewController", bundle: nil) 27 | 28 | eventMonitor = EventMonitor(mask: .LeftMouseDownMask | .RightMouseDownMask) { [unowned self] event in 29 | if self.popover.shown { 30 | self.closePopover(event) 31 | } 32 | } 33 | eventMonitor?.start() 34 | showPopover(nil) 35 | } 36 | 37 | func applicationWillTerminate(aNotification: NSNotification) { 38 | // Insert code here to tear down your application 39 | } 40 | 41 | func showPopover(sender: AnyObject?) { 42 | if let button = statusItem.button { 43 | popover.showRelativeToRect(button.bounds, ofView: button, preferredEdge: NSMinYEdge) 44 | eventMonitor?.start() 45 | } 46 | } 47 | 48 | 49 | func closePopover(sender: AnyObject?) { 50 | popover.performClose(sender) 51 | eventMonitor?.stop() 52 | } 53 | 54 | func togglePopover(sender: AnyObject?) { 55 | if popover.shown { 56 | closePopover(sender) 57 | } else { 58 | showPopover(sender) 59 | } 60 | } 61 | 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /MSC DND/Base.lproj/MainMenu.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | Default 539 | 540 | 541 | 542 | 543 | 544 | 545 | Left to Right 546 | 547 | 548 | 549 | 550 | 551 | 552 | Right to Left 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | Default 564 | 565 | 566 | 567 | 568 | 569 | 570 | Left to Right 571 | 572 | 573 | 574 | 575 | 576 | 577 | Right to Left 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | -------------------------------------------------------------------------------- /MSC DND/DNDViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DNDViewController.swift 3 | // MSC DND 4 | // 5 | // Created by Graham Gilbert on 05/07/2015. 6 | // Copyright (c) 2015 Graham Gilbert. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import CoreFoundation 11 | import Foundation 12 | 13 | class DNDViewController: NSViewController { 14 | 15 | @IBOutlet var textLabel: NSTextField! 16 | @IBOutlet var enableButton: NSButton! 17 | @IBOutlet var quitButton: NSButton! 18 | @IBOutlet var descriptionLabel: NSTextField! 19 | 20 | var dndactive = false 21 | let bundleid = "com.grahamgilbert.mscdnd" 22 | 23 | let plistPath = "/Users/Shared" 24 | var dndHours = 24 25 | var notificationsEnabled = true 26 | 27 | override func loadView() { 28 | super.loadView() 29 | activeCheck() 30 | 31 | } 32 | 33 | 34 | func activeCheck(){ 35 | let plist = plistPath.stringByAppendingPathComponent(".msc-dnd.plist") 36 | let fileManager = NSFileManager.defaultManager() 37 | if(fileManager.fileExistsAtPath(plist)) { 38 | //read in the plist, check the time 39 | var data = readDateFromPlist() 40 | let dateFormatter = NSDateFormatter() 41 | dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" 42 | let formattedDate = dateFormatter.dateFromString(data) 43 | 44 | let now = NSDate() 45 | 46 | if(formattedDate! < now) 47 | { 48 | print("Stored date is before now, reset the UI") 49 | updateDescription() 50 | enableUI() 51 | 52 | 53 | }else{ 54 | print("Stored date is after now, disable the UI and start timer") 55 | disableUI(formattedDate!.formattedWith("yyyy-MM-dd HH:mm:ss")) 56 | checkStateOnTimer() 57 | } 58 | 59 | }else{ 60 | print("file doesn't exist, set everything back to default") 61 | updateDescription() 62 | enableUI() 63 | } 64 | } 65 | 66 | func checkStateOnTimer(){ 67 | var timer = NSTimer() 68 | print("Starting timer") 69 | timer = NSTimer.scheduledTimerWithTimeInterval(15, target:self, selector: Selector("activeCheck"), userInfo: nil, repeats: false) 70 | 71 | } 72 | 73 | 74 | func updateDescription(){ 75 | let prefValue = CFPreferencesCopyAppValue("DNDHours", bundleid) as? Int 76 | 77 | if prefValue != nil { 78 | dndHours = prefValue! 79 | } 80 | 81 | var descriptionString = "" 82 | 83 | if dndHours == 1{ 84 | descriptionString = "Notifications for updates by Managed Software Center will be suppressed for \(dndHours) hour." 85 | } else{ 86 | descriptionString = "Notifications for updates by Managed Software Center will be suppressed for \(dndHours) hours." 87 | } 88 | 89 | descriptionLabel.stringValue = descriptionString 90 | 91 | } 92 | 93 | func visibleUpdate(){ 94 | descriptionLabel.hidden = false 95 | } 96 | 97 | 98 | func addHoursToCurrDateTime(hours: Int) -> String{ 99 | let seconds = hours * 60 * 60 100 | let now = NSDate(timeIntervalSinceNow:Double(seconds)) 101 | return now.formattedWith("yyyy-MM-dd HH:mm:ss") 102 | } 103 | 104 | func writeDateToPlist(date: String){ 105 | //Convert String to NSDate 106 | let dateFormatter = NSDateFormatter() 107 | dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" 108 | let formattedDate = dateFormatter.dateFromString(date) 109 | let plist = plistPath.stringByAppendingPathComponent(".msc-dnd.plist") 110 | let fileManager = NSFileManager.defaultManager() 111 | //It's easier if I start the dict off with some junk data until I know what I'm doing 112 | var dict: NSMutableDictionary = ["DNDEndDate": "DoNotEverChangeMe"] 113 | dict.setObject(formattedDate!, forKey: "DNDEndDate") 114 | dict.writeToFile(plist, atomically: false) 115 | } 116 | 117 | func readDateFromPlist() -> String{ 118 | //Make sure the file exists 119 | let plist = plistPath.stringByAppendingPathComponent(".msc-dnd.plist") 120 | let fileManager = NSFileManager.defaultManager() 121 | if(fileManager.fileExistsAtPath(plist)) { 122 | var resultDictionary = NSDictionary(contentsOfFile: plist) 123 | var date = resultDictionary!.valueForKey("DNDEndDate") as? NSDate 124 | return date!.formattedWith("yyyy-MM-dd HH:mm:ss") 125 | }else{ 126 | return "" 127 | } 128 | } 129 | 130 | func disableUI(date: String){ 131 | notificationsEnabled = false 132 | enableButton.title = "Enable Notifications" 133 | textLabel.stringValue = "Notifications Disabled" 134 | descriptionLabel.stringValue = "Notifications will resume \(date)" 135 | } 136 | 137 | func enableUI(){ 138 | notificationsEnabled = true 139 | enableButton.title = "Stop Notifications" 140 | textLabel.stringValue = "Notifications Active" 141 | updateDescription() 142 | visibleUpdate() 143 | } 144 | 145 | 146 | } 147 | 148 | extension DNDViewController { 149 | 150 | @IBAction func quit(sender: NSButton) { 151 | NSApplication.sharedApplication().terminate(sender) 152 | } 153 | 154 | @IBAction func stopNotifications(sender: AnyObject) { 155 | //Calculate the time difference 156 | let dndEndDate = addHoursToCurrDateTime(dndHours) 157 | print(notificationsEnabled) 158 | if notificationsEnabled { 159 | //Write plist 160 | writeDateToPlist(dndEndDate) 161 | //Disable ui 162 | disableUI(dndEndDate) 163 | checkStateOnTimer() 164 | } 165 | else { 166 | var error: NSError? 167 | let plist = plistPath.stringByAppendingPathComponent(".msc-dnd.plist") 168 | let fileManager = NSFileManager.defaultManager() 169 | fileManager.removeItemAtPath(plist, error: &error) 170 | enableUI() 171 | } 172 | } 173 | 174 | 175 | } 176 | 177 | extension NSDate { 178 | 179 | // you can create a read-only computed property to return just the nanoseconds as Int 180 | var nanosecond: Int { return NSCalendar.currentCalendar().component(.CalendarUnitNanosecond, fromDate: self) } 181 | 182 | // or an extension function to format your date 183 | func formattedWith(format:String)-> String { 184 | let formatter = NSDateFormatter() 185 | //formatter.timeZone = NSTimeZone(forSecondsFromGMT: 0) // you can set GMT time 186 | formatter.timeZone = NSTimeZone.localTimeZone() // or as local time 187 | formatter.dateFormat = format 188 | return formatter.stringFromDate(self) 189 | } 190 | 191 | } 192 | 193 | public func ==(lhs: NSDate, rhs: NSDate) -> Bool { 194 | return lhs === rhs || lhs.compare(rhs) == .OrderedSame 195 | } 196 | 197 | public func <(lhs: NSDate, rhs: NSDate) -> Bool { 198 | return lhs.compare(rhs) == .OrderedAscending 199 | } 200 | 201 | extension NSDate: Comparable { } 202 | -------------------------------------------------------------------------------- /MSC DND/DNDViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /MSC DND/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "size" : "32x32", 15 | "idiom" : "mac", 16 | "filename" : "hibernate@2x.png", 17 | "scale" : "1x" 18 | }, 19 | { 20 | "idiom" : "mac", 21 | "size" : "32x32", 22 | "scale" : "2x" 23 | }, 24 | { 25 | "idiom" : "mac", 26 | "size" : "128x128", 27 | "scale" : "1x" 28 | }, 29 | { 30 | "idiom" : "mac", 31 | "size" : "128x128", 32 | "scale" : "2x" 33 | }, 34 | { 35 | "idiom" : "mac", 36 | "size" : "256x256", 37 | "scale" : "1x" 38 | }, 39 | { 40 | "idiom" : "mac", 41 | "size" : "256x256", 42 | "scale" : "2x" 43 | }, 44 | { 45 | "idiom" : "mac", 46 | "size" : "512x512", 47 | "scale" : "1x" 48 | }, 49 | { 50 | "idiom" : "mac", 51 | "size" : "512x512", 52 | "scale" : "2x" 53 | } 54 | ], 55 | "info" : { 56 | "version" : 1, 57 | "author" : "xcode" 58 | } 59 | } -------------------------------------------------------------------------------- /MSC DND/Images.xcassets/AppIcon.appiconset/hibernate@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grahamgilbert/munki-dnd/f6003fd768607d66592f51c23308086ae82c044a/MSC DND/Images.xcassets/AppIcon.appiconset/hibernate@2x.png -------------------------------------------------------------------------------- /MSC DND/Images.xcassets/hibernate.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac" 5 | }, 6 | { 7 | "idiom" : "mac", 8 | "scale" : "1x" 9 | }, 10 | { 11 | "idiom" : "mac", 12 | "scale" : "2x", 13 | "filename" : "hibernate@2x.png" 14 | } 15 | ], 16 | "info" : { 17 | "version" : 1, 18 | "author" : "xcode", 19 | "template-rendering-intent" : "template" 20 | } 21 | } -------------------------------------------------------------------------------- /MSC DND/Images.xcassets/hibernate.imageset/hibernate@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grahamgilbert/munki-dnd/f6003fd768607d66592f51c23308086ae82c044a/MSC DND/Images.xcassets/hibernate.imageset/hibernate@2x.png -------------------------------------------------------------------------------- /MSC DND/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.grahamgilbert.$(PRODUCT_NAME:rfc1034identifier) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 0.0.1 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | ???? 25 | LSMinimumSystemVersion 26 | $(MACOSX_DEPLOYMENT_TARGET) 27 | LSUIElement 28 | 29 | NSHumanReadableCopyright 30 | Copyright © 2015 Graham Gilbert. All rights reserved. 31 | NSMainNibFile 32 | MainMenu 33 | NSPrincipalClass 34 | NSApplication 35 | 36 | 37 | -------------------------------------------------------------------------------- /MSC DND/hibernate@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grahamgilbert/munki-dnd/f6003fd768607d66592f51c23308086ae82c044a/MSC DND/hibernate@2x.png -------------------------------------------------------------------------------- /MSC DNDTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.grahamgilbert.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /MSC DNDTests/MSC_DNDTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MSC_DNDTests.swift 3 | // MSC DNDTests 4 | // 5 | // Created by Graham Gilbert on 05/07/2015. 6 | // Copyright (c) 2015 Graham Gilbert. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import XCTest 11 | 12 | class MSC_DNDTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | USE_PKGBUILD=1 2 | include /usr/local/share/luggage/luggage.make 3 | PACKAGE_VERSION=0.0.2 4 | TITLE=msc_dnd 5 | PACKAGE_NAME=${TITLE} 6 | REVERSE_DOMAIN=com.grahamgilbert 7 | PAYLOAD=\ 8 | pack-preflight-submit 9 | 10 | build: clean-build 11 | xcodebuild -configuration Release 12 | 13 | clean-build: 14 | @sudo rm -rf build 15 | 16 | l_munki: l_usr_local build 17 | @sudo mkdir -p ${WORK_D}/usr/local/munki/preflight.d 18 | @sudo chown root:wheel ${WORK_D}/usr/local/munki/preflight.d 19 | 20 | pack-preflight-submit: l_munki l_Applications 21 | @sudo ${CP} -R "build/Release/Managed Software Center DND.app" ${WORK_D}/Applications/Managed\ Software\ Center\ DND.app 22 | @sudo chown -R root:wheel ${WORK_D}/Applications/Managed\ Software\ Center\ DND.app 23 | @sudo ${CP} munki-dnd.py ${WORK_D}/usr/local/munki/preflight.d/munki-dnd.py 24 | @sudo chown -R root:wheel ${WORK_D}/usr/local/munki/preflight.d/munki-dnd.py 25 | @sudo chmod -R 755 ${WORK_D}/usr/local/munki/preflight.d/munki-dnd.py 26 | -------------------------------------------------------------------------------- /Managed Software Center DND.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | FC372EA31B494F26008E258A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC372EA21B494F26008E258A /* AppDelegate.swift */; }; 11 | FC372EA51B494F26008E258A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FC372EA41B494F26008E258A /* Images.xcassets */; }; 12 | FC372EA81B494F26008E258A /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = FC372EA61B494F26008E258A /* MainMenu.xib */; }; 13 | FC372EB41B494F26008E258A /* MSC_DNDTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC372EB31B494F26008E258A /* MSC_DNDTests.swift */; }; 14 | FC55CBDB1B495507007A8BC8 /* DNDViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC55CBD91B495507007A8BC8 /* DNDViewController.swift */; }; 15 | FC55CBDC1B495507007A8BC8 /* DNDViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = FC55CBDA1B495507007A8BC8 /* DNDViewController.xib */; }; 16 | FC55CBE01B497644007A8BC8 /* EventMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC55CBDF1B497644007A8BC8 /* EventMonitor.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | FC372EAE1B494F26008E258A /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = FC372E951B494F26008E258A /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = FC372E9C1B494F26008E258A; 25 | remoteInfo = "MSC DND"; 26 | }; 27 | /* End PBXContainerItemProxy section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | FC372E9D1B494F26008E258A /* Managed Software Center DND.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Managed Software Center DND.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | FC372EA11B494F26008E258A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | FC372EA21B494F26008E258A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33 | FC372EA41B494F26008E258A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 34 | FC372EA71B494F26008E258A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 35 | FC372EAD1B494F26008E258A /* Managed Software Center DNDTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Managed Software Center DNDTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | FC372EB21B494F26008E258A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | FC372EB31B494F26008E258A /* MSC_DNDTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSC_DNDTests.swift; sourceTree = ""; }; 38 | FC55CBD91B495507007A8BC8 /* DNDViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DNDViewController.swift; sourceTree = ""; }; 39 | FC55CBDA1B495507007A8BC8 /* DNDViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DNDViewController.xib; sourceTree = ""; }; 40 | FC55CBDF1B497644007A8BC8 /* EventMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EventMonitor.swift; path = ../EventMonitor.swift; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | FC372E9A1B494F26008E258A /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | FC372EAA1B494F26008E258A /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | /* End PBXFrameworksBuildPhase section */ 59 | 60 | /* Begin PBXGroup section */ 61 | FC372E941B494F26008E258A = { 62 | isa = PBXGroup; 63 | children = ( 64 | FC372E9F1B494F26008E258A /* MSC DND */, 65 | FC372EB01B494F26008E258A /* MSC DNDTests */, 66 | FC372E9E1B494F26008E258A /* Products */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | FC372E9E1B494F26008E258A /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | FC372E9D1B494F26008E258A /* Managed Software Center DND.app */, 74 | FC372EAD1B494F26008E258A /* Managed Software Center DNDTests.xctest */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | FC372E9F1B494F26008E258A /* MSC DND */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | FC55CBDF1B497644007A8BC8 /* EventMonitor.swift */, 83 | FC372EA21B494F26008E258A /* AppDelegate.swift */, 84 | FC55CBD91B495507007A8BC8 /* DNDViewController.swift */, 85 | FC55CBDA1B495507007A8BC8 /* DNDViewController.xib */, 86 | FC372EA41B494F26008E258A /* Images.xcassets */, 87 | FC372EA61B494F26008E258A /* MainMenu.xib */, 88 | FC372EA01B494F26008E258A /* Supporting Files */, 89 | ); 90 | path = "MSC DND"; 91 | sourceTree = ""; 92 | }; 93 | FC372EA01B494F26008E258A /* Supporting Files */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | FC372EA11B494F26008E258A /* Info.plist */, 97 | ); 98 | name = "Supporting Files"; 99 | sourceTree = ""; 100 | }; 101 | FC372EB01B494F26008E258A /* MSC DNDTests */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | FC372EB31B494F26008E258A /* MSC_DNDTests.swift */, 105 | FC372EB11B494F26008E258A /* Supporting Files */, 106 | ); 107 | path = "MSC DNDTests"; 108 | sourceTree = ""; 109 | }; 110 | FC372EB11B494F26008E258A /* Supporting Files */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | FC372EB21B494F26008E258A /* Info.plist */, 114 | ); 115 | name = "Supporting Files"; 116 | sourceTree = ""; 117 | }; 118 | /* End PBXGroup section */ 119 | 120 | /* Begin PBXNativeTarget section */ 121 | FC372E9C1B494F26008E258A /* Managed Software Center DND */ = { 122 | isa = PBXNativeTarget; 123 | buildConfigurationList = FC372EB71B494F26008E258A /* Build configuration list for PBXNativeTarget "Managed Software Center DND" */; 124 | buildPhases = ( 125 | FC372E991B494F26008E258A /* Sources */, 126 | FC372E9A1B494F26008E258A /* Frameworks */, 127 | FC372E9B1B494F26008E258A /* Resources */, 128 | FC87C33C1B4A99CA0028F05D /* ShellScript */, 129 | ); 130 | buildRules = ( 131 | ); 132 | dependencies = ( 133 | ); 134 | name = "Managed Software Center DND"; 135 | productName = "MSC DND"; 136 | productReference = FC372E9D1B494F26008E258A /* Managed Software Center DND.app */; 137 | productType = "com.apple.product-type.application"; 138 | }; 139 | FC372EAC1B494F26008E258A /* Managed Software Center DNDTests */ = { 140 | isa = PBXNativeTarget; 141 | buildConfigurationList = FC372EBA1B494F26008E258A /* Build configuration list for PBXNativeTarget "Managed Software Center DNDTests" */; 142 | buildPhases = ( 143 | FC372EA91B494F26008E258A /* Sources */, 144 | FC372EAA1B494F26008E258A /* Frameworks */, 145 | FC372EAB1B494F26008E258A /* Resources */, 146 | ); 147 | buildRules = ( 148 | ); 149 | dependencies = ( 150 | FC372EAF1B494F26008E258A /* PBXTargetDependency */, 151 | ); 152 | name = "Managed Software Center DNDTests"; 153 | productName = "MSC DNDTests"; 154 | productReference = FC372EAD1B494F26008E258A /* Managed Software Center DNDTests.xctest */; 155 | productType = "com.apple.product-type.bundle.unit-test"; 156 | }; 157 | /* End PBXNativeTarget section */ 158 | 159 | /* Begin PBXProject section */ 160 | FC372E951B494F26008E258A /* Project object */ = { 161 | isa = PBXProject; 162 | attributes = { 163 | LastUpgradeCheck = 0640; 164 | ORGANIZATIONNAME = "Graham Gilbert"; 165 | TargetAttributes = { 166 | FC372E9C1B494F26008E258A = { 167 | CreatedOnToolsVersion = 6.4; 168 | }; 169 | FC372EAC1B494F26008E258A = { 170 | CreatedOnToolsVersion = 6.4; 171 | TestTargetID = FC372E9C1B494F26008E258A; 172 | }; 173 | }; 174 | }; 175 | buildConfigurationList = FC372E981B494F26008E258A /* Build configuration list for PBXProject "Managed Software Center DND" */; 176 | compatibilityVersion = "Xcode 3.2"; 177 | developmentRegion = English; 178 | hasScannedForEncodings = 0; 179 | knownRegions = ( 180 | en, 181 | Base, 182 | ); 183 | mainGroup = FC372E941B494F26008E258A; 184 | productRefGroup = FC372E9E1B494F26008E258A /* Products */; 185 | projectDirPath = ""; 186 | projectRoot = ""; 187 | targets = ( 188 | FC372E9C1B494F26008E258A /* Managed Software Center DND */, 189 | FC372EAC1B494F26008E258A /* Managed Software Center DNDTests */, 190 | ); 191 | }; 192 | /* End PBXProject section */ 193 | 194 | /* Begin PBXResourcesBuildPhase section */ 195 | FC372E9B1B494F26008E258A /* Resources */ = { 196 | isa = PBXResourcesBuildPhase; 197 | buildActionMask = 2147483647; 198 | files = ( 199 | FC372EA51B494F26008E258A /* Images.xcassets in Resources */, 200 | FC372EA81B494F26008E258A /* MainMenu.xib in Resources */, 201 | FC55CBDC1B495507007A8BC8 /* DNDViewController.xib in Resources */, 202 | ); 203 | runOnlyForDeploymentPostprocessing = 0; 204 | }; 205 | FC372EAB1B494F26008E258A /* Resources */ = { 206 | isa = PBXResourcesBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | ); 210 | runOnlyForDeploymentPostprocessing = 0; 211 | }; 212 | /* End PBXResourcesBuildPhase section */ 213 | 214 | /* Begin PBXShellScriptBuildPhase section */ 215 | FC87C33C1B4A99CA0028F05D /* ShellScript */ = { 216 | isa = PBXShellScriptBuildPhase; 217 | buildActionMask = 2147483647; 218 | files = ( 219 | ); 220 | inputPaths = ( 221 | ); 222 | outputPaths = ( 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | shellPath = /bin/sh; 226 | shellScript = "# based on http://tgoode.com/2014/06/05/sensible-way-increment-bundle-version-cfbundleversion-xcode\nif git rev-parse --is-inside-work-tree 2> /dev/null > /dev/null; then\necho \"Setting CFBundleVersion to Git rev-list --count\"\nbuild_number=$(git rev-list HEAD --count)\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $build_number\" \"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}\"\nelse\necho \"Not in a Git repo, not setting CFBundleVersion\"\nfi\n"; 227 | }; 228 | /* End PBXShellScriptBuildPhase section */ 229 | 230 | /* Begin PBXSourcesBuildPhase section */ 231 | FC372E991B494F26008E258A /* Sources */ = { 232 | isa = PBXSourcesBuildPhase; 233 | buildActionMask = 2147483647; 234 | files = ( 235 | FC55CBE01B497644007A8BC8 /* EventMonitor.swift in Sources */, 236 | FC372EA31B494F26008E258A /* AppDelegate.swift in Sources */, 237 | FC55CBDB1B495507007A8BC8 /* DNDViewController.swift in Sources */, 238 | ); 239 | runOnlyForDeploymentPostprocessing = 0; 240 | }; 241 | FC372EA91B494F26008E258A /* Sources */ = { 242 | isa = PBXSourcesBuildPhase; 243 | buildActionMask = 2147483647; 244 | files = ( 245 | FC372EB41B494F26008E258A /* MSC_DNDTests.swift in Sources */, 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | }; 249 | /* End PBXSourcesBuildPhase section */ 250 | 251 | /* Begin PBXTargetDependency section */ 252 | FC372EAF1B494F26008E258A /* PBXTargetDependency */ = { 253 | isa = PBXTargetDependency; 254 | target = FC372E9C1B494F26008E258A /* Managed Software Center DND */; 255 | targetProxy = FC372EAE1B494F26008E258A /* PBXContainerItemProxy */; 256 | }; 257 | /* End PBXTargetDependency section */ 258 | 259 | /* Begin PBXVariantGroup section */ 260 | FC372EA61B494F26008E258A /* MainMenu.xib */ = { 261 | isa = PBXVariantGroup; 262 | children = ( 263 | FC372EA71B494F26008E258A /* Base */, 264 | ); 265 | name = MainMenu.xib; 266 | sourceTree = ""; 267 | }; 268 | /* End PBXVariantGroup section */ 269 | 270 | /* Begin XCBuildConfiguration section */ 271 | FC372EB51B494F26008E258A /* Debug */ = { 272 | isa = XCBuildConfiguration; 273 | buildSettings = { 274 | ALWAYS_SEARCH_USER_PATHS = NO; 275 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 276 | CLANG_CXX_LIBRARY = "libc++"; 277 | CLANG_ENABLE_MODULES = YES; 278 | CLANG_ENABLE_OBJC_ARC = YES; 279 | CLANG_WARN_BOOL_CONVERSION = YES; 280 | CLANG_WARN_CONSTANT_CONVERSION = YES; 281 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 282 | CLANG_WARN_EMPTY_BODY = YES; 283 | CLANG_WARN_ENUM_CONVERSION = YES; 284 | CLANG_WARN_INT_CONVERSION = YES; 285 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 286 | CLANG_WARN_UNREACHABLE_CODE = YES; 287 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 288 | CODE_SIGN_IDENTITY = "-"; 289 | COPY_PHASE_STRIP = NO; 290 | DEBUG_INFORMATION_FORMAT = dwarf; 291 | ENABLE_STRICT_OBJC_MSGSEND = YES; 292 | GCC_C_LANGUAGE_STANDARD = gnu99; 293 | GCC_DYNAMIC_NO_PIC = NO; 294 | GCC_NO_COMMON_BLOCKS = YES; 295 | GCC_OPTIMIZATION_LEVEL = 0; 296 | GCC_PREPROCESSOR_DEFINITIONS = ( 297 | "DEBUG=1", 298 | "$(inherited)", 299 | ); 300 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 301 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 302 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 303 | GCC_WARN_UNDECLARED_SELECTOR = YES; 304 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 305 | GCC_WARN_UNUSED_FUNCTION = YES; 306 | GCC_WARN_UNUSED_VARIABLE = YES; 307 | MACOSX_DEPLOYMENT_TARGET = 10.10; 308 | MTL_ENABLE_DEBUG_INFO = YES; 309 | ONLY_ACTIVE_ARCH = YES; 310 | SDKROOT = macosx; 311 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 312 | }; 313 | name = Debug; 314 | }; 315 | FC372EB61B494F26008E258A /* Release */ = { 316 | isa = XCBuildConfiguration; 317 | buildSettings = { 318 | ALWAYS_SEARCH_USER_PATHS = NO; 319 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 320 | CLANG_CXX_LIBRARY = "libc++"; 321 | CLANG_ENABLE_MODULES = YES; 322 | CLANG_ENABLE_OBJC_ARC = YES; 323 | CLANG_WARN_BOOL_CONVERSION = YES; 324 | CLANG_WARN_CONSTANT_CONVERSION = YES; 325 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 326 | CLANG_WARN_EMPTY_BODY = YES; 327 | CLANG_WARN_ENUM_CONVERSION = YES; 328 | CLANG_WARN_INT_CONVERSION = YES; 329 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 330 | CLANG_WARN_UNREACHABLE_CODE = YES; 331 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 332 | CODE_SIGN_IDENTITY = "-"; 333 | COPY_PHASE_STRIP = NO; 334 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 335 | ENABLE_NS_ASSERTIONS = NO; 336 | ENABLE_STRICT_OBJC_MSGSEND = YES; 337 | GCC_C_LANGUAGE_STANDARD = gnu99; 338 | GCC_NO_COMMON_BLOCKS = YES; 339 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 340 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 341 | GCC_WARN_UNDECLARED_SELECTOR = YES; 342 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 343 | GCC_WARN_UNUSED_FUNCTION = YES; 344 | GCC_WARN_UNUSED_VARIABLE = YES; 345 | MACOSX_DEPLOYMENT_TARGET = 10.10; 346 | MTL_ENABLE_DEBUG_INFO = NO; 347 | SDKROOT = macosx; 348 | }; 349 | name = Release; 350 | }; 351 | FC372EB81B494F26008E258A /* Debug */ = { 352 | isa = XCBuildConfiguration; 353 | buildSettings = { 354 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 355 | COMBINE_HIDPI_IMAGES = YES; 356 | INFOPLIST_FILE = "MSC DND/Info.plist"; 357 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 358 | PRODUCT_NAME = "Managed Software Center DND"; 359 | }; 360 | name = Debug; 361 | }; 362 | FC372EB91B494F26008E258A /* Release */ = { 363 | isa = XCBuildConfiguration; 364 | buildSettings = { 365 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 366 | COMBINE_HIDPI_IMAGES = YES; 367 | INFOPLIST_FILE = "MSC DND/Info.plist"; 368 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 369 | PRODUCT_NAME = "Managed Software Center DND"; 370 | }; 371 | name = Release; 372 | }; 373 | FC372EBB1B494F26008E258A /* Debug */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | BUNDLE_LOADER = "$(TEST_HOST)"; 377 | COMBINE_HIDPI_IMAGES = YES; 378 | FRAMEWORK_SEARCH_PATHS = ( 379 | "$(DEVELOPER_FRAMEWORKS_DIR)", 380 | "$(inherited)", 381 | ); 382 | GCC_PREPROCESSOR_DEFINITIONS = ( 383 | "DEBUG=1", 384 | "$(inherited)", 385 | ); 386 | INFOPLIST_FILE = "MSC DNDTests/Info.plist"; 387 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 388 | PRODUCT_NAME = "Managed Software Center DNDTests"; 389 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Managed Software Center DND.app/Contents/MacOS/Managed Software Center DND"; 390 | }; 391 | name = Debug; 392 | }; 393 | FC372EBC1B494F26008E258A /* Release */ = { 394 | isa = XCBuildConfiguration; 395 | buildSettings = { 396 | BUNDLE_LOADER = "$(TEST_HOST)"; 397 | COMBINE_HIDPI_IMAGES = YES; 398 | FRAMEWORK_SEARCH_PATHS = ( 399 | "$(DEVELOPER_FRAMEWORKS_DIR)", 400 | "$(inherited)", 401 | ); 402 | INFOPLIST_FILE = "MSC DNDTests/Info.plist"; 403 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 404 | PRODUCT_NAME = "Managed Software Center DNDTests"; 405 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Managed Software Center DND.app/Contents/MacOS/Managed Software Center DND"; 406 | }; 407 | name = Release; 408 | }; 409 | /* End XCBuildConfiguration section */ 410 | 411 | /* Begin XCConfigurationList section */ 412 | FC372E981B494F26008E258A /* Build configuration list for PBXProject "Managed Software Center DND" */ = { 413 | isa = XCConfigurationList; 414 | buildConfigurations = ( 415 | FC372EB51B494F26008E258A /* Debug */, 416 | FC372EB61B494F26008E258A /* Release */, 417 | ); 418 | defaultConfigurationIsVisible = 0; 419 | defaultConfigurationName = Release; 420 | }; 421 | FC372EB71B494F26008E258A /* Build configuration list for PBXNativeTarget "Managed Software Center DND" */ = { 422 | isa = XCConfigurationList; 423 | buildConfigurations = ( 424 | FC372EB81B494F26008E258A /* Debug */, 425 | FC372EB91B494F26008E258A /* Release */, 426 | ); 427 | defaultConfigurationIsVisible = 0; 428 | defaultConfigurationName = Release; 429 | }; 430 | FC372EBA1B494F26008E258A /* Build configuration list for PBXNativeTarget "Managed Software Center DNDTests" */ = { 431 | isa = XCConfigurationList; 432 | buildConfigurations = ( 433 | FC372EBB1B494F26008E258A /* Debug */, 434 | FC372EBC1B494F26008E258A /* Release */, 435 | ); 436 | defaultConfigurationIsVisible = 0; 437 | defaultConfigurationName = Release; 438 | }; 439 | /* End XCConfigurationList section */ 440 | }; 441 | rootObject = FC372E951B494F26008E258A /* Project object */; 442 | } 443 | -------------------------------------------------------------------------------- /Managed Software Center DND.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # munki-dnd 2 | A 'do not disturb' menubar app for Munki for Yosemite and above. 3 | 4 | ![Active](https://github.com/grahamgilbert/munki-dnd/blob/master/images/active.png) 5 | 6 | ![Inactive](https://github.com/grahamgilbert/munki-dnd/blob/master/images/disabled.png) 7 | 8 | ## Usage 9 | 10 | By default, this will suppress user notifications from MSC for 24 hours. To adjust this period, use the following: 11 | 12 | ``` bash 13 | $ defaults write /Library/Preferences/com.grahamgilbert.mscdnd DNDHours -int 1 14 | ``` 15 | 16 | Where ``1`` is the number of hours you want to allow the user to suppress notifications for. 17 | 18 | ## What's happening? 19 | 20 | The package installs two things: the client application that allows users to suppress notifications, and a Munki preflight script that will read in a file created by the app (in ``/Users/Shared/.msc-dnd.plist`` if you care about such things) and the change the ``SuppressUserNotification`` in Munki appropriately depending on whether the specified time has elapsed or not. 21 | 22 | ## Troubleshooting 23 | 24 | This tool sets ``SuppressUserNotification`` in ``/Library/Preferences/ManagedInstalls.plist``. If you are setting this preference via a Profile or MCX, this application will have no effect. 25 | 26 | This app is written in Swift, so requires OS X 10.10 or later. 27 | 28 | The preflight script assumes you have some method of running scripts in ``/usr/local/munki/preflight.d``. If you are using Sal, or munkireport-php, you will have everything you need to just use the package as is. If you are not, you will need to move the script to ``/usr/local/munki/preflight``. 29 | 30 | Thanks to [Icons8](https://icons8.com) for the app icon. 31 | -------------------------------------------------------------------------------- /images/active.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grahamgilbert/munki-dnd/f6003fd768607d66592f51c23308086ae82c044a/images/active.png -------------------------------------------------------------------------------- /images/disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grahamgilbert/munki-dnd/f6003fd768607d66592f51c23308086ae82c044a/images/disabled.png -------------------------------------------------------------------------------- /munki-dnd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | # try to import from the default place Munki installs it 5 | try: 6 | from munkilib import FoundationPlist, munkicommon 7 | except: 8 | sys.path.append('/usr/local/munki') 9 | from munkilib import FoundationPlist, munkicommon 10 | 11 | import os 12 | from datetime import datetime 13 | 14 | FILE_LOCATION = "/Users/Shared/.msc-dnd.plist" 15 | 16 | # Does the file exist? 17 | if not os.path.isfile(FILE_LOCATION): 18 | # File isn't here, set the Munki pref to False 19 | munkicommon.set_pref('SuppressUserNotification', False) 20 | sys.exit(0) 21 | 22 | # If it does, get the current date? 23 | else: 24 | plist = FoundationPlist.readPlist(FILE_LOCATION) 25 | if 'DNDEndDate' not in plist: 26 | # The key we need isn't in there, remove the file, set pref and exit 27 | os.remove(FILE_LOCATION) 28 | munkicommon.set_pref('SuppressUserNotification', False) 29 | sys.exit(0) 30 | else: 31 | # Is the current date greater than the DND date? 32 | saved_time = datetime.strptime(str(plist['DNDEndDate']), "%Y-%m-%d %H:%M:%S +0000") 33 | current_time = datetime.now() 34 | if saved_time < current_time: 35 | # print "Current time is greater" 36 | # If yes, remove the file and set the Munki pref for suppress notifications to False 37 | os.remove(FILE_LOCATION) 38 | munkicommon.set_pref('SuppressUserNotification', False) 39 | sys.exit(0) 40 | else: 41 | # print "Saved Time is greater" 42 | munkicommon.set_pref('SuppressUserNotification', True) 43 | sys.exit(0) 44 | # If no, make sure suppress notifications is True 45 | --------------------------------------------------------------------------------