     applescript.execString(script)
 
   refreshProject: ->
-    newPanel = atom.workspace.getActivePaneItem()
-    if newPanel
-      if newPanel.buffer
-        if newPanel.buffer.file
-          script = "tell application \"CodeKit\" to select project containing path \"#{newPanel.buffer.file.path}\""
-          applescript.execString(script)
+    @switchProject(atom.workspace.getActivePaneItem())
     script = 'tell application \"CodeKit\" to refresh browsers'
     applescript.execString(script)
 

  subscriptions: null

  activate: ->
    @switchProject(atom.workspace.getActivePaneItem())
    @subscriptions = new CompositeDisposable
    @subscriptions.add atom.commands.add 'atom-workspace', 'codekit-commands:previewProject': => @previewProject()
    @subscriptions.add atom.commands.add 'atom-workspace', 'codekit-commands:refreshProject': => @refreshProject()
    @subscriptions.add atom.commands.add '.project-root > .header', 'codekit-commands:addProject': => @addProject()
    @subscriptions.add atom.workspace.onDidChangeActivePaneItem (callback) => @switchProject(callback)
    @subscriptions.add $(window).on 'load', => @startCodekit()
    @subscriptions.add $(window).on 'unload', => @quitCodekit()
    @subscriptions.add $(window).on 'blur', => @pauseProject()


  startCodekit: ->
    if atom.config.get('codekit-commands.autoStart')
      @switchProject(atom.workspace.getActivePaneItem())
      script = 'tell application "CodeKit" to launch'
      applescript.execString(script)

