-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Method for enabling Do Not Disturb Mode * Add Method for disabling Do Not Disturb Mode
- Loading branch information
1 parent
8e4bb5b
commit e2a4ed6
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"time" | ||
) | ||
|
||
func restartNotificationCenter() error { | ||
cmd := exec.Command("bash", "-c", "killall NotificationCenter") | ||
|
||
_, err := cmd.Output() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// TurnDoNotDisturbOn turns on Do Not Disturb on Mac OS X | ||
func TurnDoNotDisturbOn() error { | ||
|
||
// Enable Do Not Disturb Mode | ||
cmd := exec.Command("bash", "-c", "defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true") | ||
|
||
_, err := cmd.CombinedOutput() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Set Time forDo Not Disturb Mode | ||
t := time.Now() | ||
tfmt := fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d +0000", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second()) | ||
|
||
cmd = exec.Command("bash", "-c", fmt.Sprintf("defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date '%s'", tfmt)) | ||
|
||
_, err = cmd.CombinedOutput() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Restart Notification Center | ||
err = restartNotificationCenter() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// TurnDoNotDisturbOff turns off Do Not Disturb on Mac OS X | ||
func TurnDoNotDisturbOff() error { | ||
|
||
// Disable Do Not Disturb Mode | ||
cmd := exec.Command("bash", "-c", "defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false") | ||
|
||
_, err := cmd.CombinedOutput() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Restart Notification Center | ||
err = restartNotificationCenter() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters