title: How do I adjust a slider to show the current brightness level on Mac OSX using Swift?
body: <p>I have created a slider that allows me to control the brightness on my Mac. I'm trying to make sure the slider accurately represents the current brightness level. If I change the brightness via the keyboard, I want the slider to reflect the new level.</p>
  
  <p>Right now the slider will show me the current brightness level, but only after I click the slider. Furthermore, I cannot change the brightness from the slider.</p>
  
  <pre><code>@IBAction func brightnessSlider(sender: NSSlider) {
      verticalSlider.floatValue = getBrightnessLevel()
      setBrightnessLevel(sender.floatValue)
  }
  </code></pre>
  
  <p>If I remove the line trying to get the brightness, I can adjust the brightness level from the slider, but it always starts out as maxed out.</p>
  
  <p>How can I have the slider be both adjustable and always reflect the brightness level?</p>
  
  <p>Also, <a href="https://github.com/spearskw/BrightnessMenu" rel="nofollow">here's a link</a> to the full source if it's helpful.</p>
  
  <p>EDIT:
  I'm able to have the slider display the correct brightness when I click on the menu with the following code, but it still doesn't update while it's open. Also, updating while it's closed seems like a bad idea.</p>
  
  <pre><code>NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: Selector("updateBrightnessSlider"), userInfo: nil, repeats: true)
  </code></pre>