With patience, treats, and a little practice, your dog can learn this surprisingly useful trick. Here’s how we did it.