├── .gitignore ├── LICENSE ├── README.md ├── goreleaser.yml └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | # goreleaser files 2 | dist/ 3 | 4 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 5 | *.o 6 | *.a 7 | *.so 8 | 9 | # Folders 10 | _obj 11 | _test 12 | .DS_Store 13 | 14 | # Architecture specific extensions/prefixes 15 | *.[568vq] 16 | [568vq].out 17 | 18 | *.cgo1.go 19 | *.cgo2.c 20 | _cgo_defun.c 21 | _cgo_gotypes.go 22 | _cgo_export.* 23 | 24 | _testmain.go 25 | 26 | *.exe 27 | *.test 28 | *.prof 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Michael 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dontdisturb 2 | 3 | Small program to enable "Do not disturb" mode on **OSX** for X minutes, 4 | since OSX only allows for setting this for the rest of the day. 5 | 6 | ## Install 7 | ### Use a Release 8 | 9 | Grab the latest release from [here](https://github.com/embano1/dontdisturb/releases). 10 | 11 | ### Build from Source 12 | 13 | `go get -u github.com/embano1/dontdisturb` 14 | 15 | ## Run (default: 15min) 16 | 17 | make sure $GOPATH/bin is in your path, then: `dontdisturb` 18 | 19 | ## Option -t [minutes] 20 | 21 | Enable "Do not disturb" for 10 minutes: `dontdisturb -t 10` 22 | -------------------------------------------------------------------------------- /goreleaser.yml: -------------------------------------------------------------------------------- 1 | # goreleaser.yml 2 | # Build customization 3 | build: 4 | binary: dontdisturb 5 | goos: 6 | - darwin 7 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | "os/exec" 8 | "os/signal" 9 | "syscall" 10 | "time" 11 | ) 12 | 13 | var min int 14 | 15 | func main() { 16 | 17 | // Make sure we enable Notifitcations when the program exits 18 | defer disableDND() 19 | flag.IntVar(&min, "t", 15, "Time in minutes for 'Do not disturb' mode") 20 | flag.Parse() 21 | 22 | timerChan := time.NewTimer(time.Minute * time.Duration(min)).C 23 | tickerChan := time.NewTicker(time.Minute * 1).C 24 | sigChan := make(chan os.Signal, 1) 25 | signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) 26 | 27 | go enableDND() 28 | 29 | for { 30 | select { 31 | case <-timerChan: 32 | return 33 | case <-tickerChan: 34 | min-- 35 | fmt.Printf("Turning off 'Do not disturb' mode in %d minutes\n", min) 36 | case <-sigChan: 37 | fmt.Println("Got SIGTERM") 38 | return 39 | } 40 | } 41 | 42 | } 43 | 44 | func enableDND() { 45 | fmt.Printf("Turning on 'Do not disturb' mode for %d minutes\n", min) 46 | 47 | cmd := exec.Command("sh", "-c", "defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true") 48 | _, err := cmd.CombinedOutput() 49 | if err != nil { 50 | fmt.Fprintf(os.Stderr, "error: could not set doNotDisturb to true: %v", err) 51 | os.Exit(1) 52 | } 53 | 54 | cmd = exec.Command("sh", "-c", "defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date \"`date -u +\"%Y-%m-%d %H:%M:%S +000\"`\"") 55 | _, err = cmd.CombinedOutput() 56 | if err != nil { 57 | fmt.Fprintf(os.Stderr, "error: could not write time to ~/Library/Preferences/ByHost/com.apple.notificationcenterui: %v", err) 58 | os.Exit(1) 59 | } 60 | 61 | cmd = exec.Command("sh", "-c", "killall NotificationCenter") 62 | _, err = cmd.CombinedOutput() 63 | if err != nil { 64 | fmt.Fprintf(os.Stderr, "error: could not reset NotificationCenter: %v", err) 65 | os.Exit(1) 66 | } 67 | } 68 | 69 | func disableDND() { 70 | cmd := exec.Command("sh", "-c", "defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false") 71 | _, err := cmd.CombinedOutput() 72 | if err != nil { 73 | fmt.Fprintf(os.Stderr, "error: could not set doNotDisturb to false: %v", err) 74 | os.Exit(1) 75 | } 76 | 77 | cmd = exec.Command("sh", "-c", "killall NotificationCenter") 78 | _, err = cmd.CombinedOutput() 79 | if err != nil { 80 | fmt.Fprintf(os.Stderr, "error: could not reset NotificationCenter: %v", err) 81 | os.Exit(1) 82 | } 83 | 84 | fmt.Println("Turning off 'Do not disturb' mode") 85 | } 86 | --------------------------------------------------------------------------------