title: If frame named "xyz" exists, then switch to that frame
body: <p>Could someone please give me hand with a function that detects whether a frame named "xyz" exists, and if so, then switch to that frame.  I'm using <code>frame-cmds</code> to give each frame a user-defined name:  <a href="http://www.emacswiki.org/emacs/frame-cmds.el" rel="nofollow noreferrer">http://www.emacswiki.org/emacs/frame-cmds.el</a></p>
  
  <p>I would imagine it is similar to a buffer, but I'm not finding anything on Google.  Here is the buffer function:</p>
  
  <pre><code>(defun buffer-exists (bufname)
      (not (eq nil (get-buffer bufname))))
  
  (defun lawlist-switch-to-buffer-xyz ()
  (interactive)
      (if (buffer-exists "xyz")
          (switch-to-buffer "xyz") ))
  </code></pre>
  
  <p>Here is a semi-related post:  <a href="https://superuser.com/questions/358037/emacsclient-create-a-frame-if-a-frame-does-not-exist">https://superuser.com/questions/358037/emacsclient-create-a-frame-if-a-frame-does-not-exist</a></p>
  
  <hr>
  
  <p><strong>EDIT</strong> (September 15, 2014):  Modified the function <code>ido-switch-frame</code> to make <code>frame-to</code> a let-bound variable, and removed the <code>message</code>.  Removed previous edits as the functions <code>get-a-frame</code> and <code>get-frame-name</code> written by Drew Adams are sufficient when used in conjunction with <code>select-frame-set-input-focus</code> -- see his answer below.</p>
  
    <pre class="lang-lisp prettyprint-override"><code>(defun ido-switch-frame ()
  (interactive)
    (when (not (minibufferp))
      (let* (
          (frames (frame-list))
          (frame-to (ido-completing-read "Select Frame:  "
            (mapcar (lambda (frame) (frame-parameter frame 'name)) frames))))
        (catch 'break
          (while frames
            (let ((frame (car frames)))
              (if (equal (frame-parameter frame 'name) frame-to)
                (throw 'break (select-frame-set-input-focus frame))
                (setq frames (cdr frames)))))))))
  </code></pre>