 
 (declare device-agents)
 
+(defn wait-for-device [dev]
+  (when (and dev (pos? (.length dev)))
+    (core waitForDevice dev)))
+
 (defn create-device-agents []
   (def device-agents
     (let [devs (seq (core getLoadedDevices))]

  (with-core-setting [getAutoShutter setAutoShutter false]
    (if open-before
      (core setShutterOpen true)
      (core waitForDevice (core getShutterDevice)))
    (core snapImage)
    (if close-after
      (core setShutterOpen false))
      (core waitForDevice (core getShutterDevice))))

(defn init-burst [length]
  (core setAutoShutter (@state :init-auto-shutter))

      (doall (map (partial await-for 10000) (vals device-agents))))
    (do
      (doseq [[dev action] action-map]
        (action) (wait-for-device dev)))))

(defn run-autofocus []
  (.. gui getAutofocusManager getDevice fullFocus)
