 import Cocoa
 import AudioToolbox
 
+// TODO Add function to check device (simplifies repeated if checks
+
 @NSApplicationMain
 class AppDelegate: NSObject, NSApplicationDelegate {
+  let desiredVolumeKey: String = "desiredVolume"
+  
   func applicationDidFinishLaunching(_ aNotification: Notification) {
-    let defaultOutputDeviceID: AudioDeviceID?
+    // ---
+    var defaultOutputDeviceID: AudioDeviceID? = kAudioObjectUnknown // TODO Remove default assigned value?
     do {
       try defaultOutputDeviceID = getDefaultOutputDevice()
       NSLog("Default output device ID: \(defaultOutputDeviceID)")

    nc.addObserver(forName: NSNotification.Name.NSWorkspaceDidWake, object: nil, queue: nil) { (notification: Notification) in
      NSLog("Workspace did wake")
      NSLog(notification.description)
    }
  }


      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
