     nc.addObserver(forName: NSNotification.Name.NSWorkspaceDidWake, object: nil, queue: nil) { (notification: Notification) in
       NSLog("Workspace did wake")
       NSLog(notification.description)
+      guard defaultOutputDeviceID != nil && defaultOutputDeviceID != kAudioObjectUnknown else {
+        NSLog("defaultOutputDeviceID invalid")
+        return
+      }
+      
+
+      do {
+        try setDeviceVolume(outputDeviceID: defaultOutputDeviceID!, value: desiredVolume)
+      } catch VolumeError.failedToSetVolume {
+          
+      } catch VolumeError.outputDeviceHasNoVolumeProperty {
+          
+      } catch {
+      
+      }
+
     }
   }
 

import Cocoa
import AudioToolbox

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
  func applicationDidFinishLaunching(_ aNotification: Notification) {
    let defaultOutputDeviceID: AudioDeviceID?
    do {
      try defaultOutputDeviceID = getDefaultOutputDevice()
      NSLog("Default output device ID: \(defaultOutputDeviceID)")

      NSLog("No default output device found")
    }
    
    // ---
    let defaults = UserDefaults.standard
    defaults.set(0.0, forKey: desiredVolumeKey)
    var desiredVolume = defaults.float(forKey: desiredVolumeKey)
    
    // ---
    NSLog("Setting up will sleep & did wake notifications")
    let nc = NSWorkspace.shared().notificationCenter
    nc.addObserver(forName: NSNotification.Name.NSWorkspaceWillSleep, object: nil, queue: nil) { (notification: Notification) in
