Do what I do...look around, squirm in your seat uncomfortably, take out your purse/wallet and start going through it, look around again, give up and sip on an empty glass, look around again, look quizzically at your companion, watch the TV over the bar as if you understand the soccer match that's on, look around again, make eye contact with the waiter and smile, fiddle with your wallet again, stand up, sit down, sip empty glass once more, stand up and put on jacket, sit down and stare at TV again, smile at OTHER waiter, then FINALLY do what Eddie suggests and gesture to the waiter/waitress with a little "writing" motion.
Pay, leave, and spend the next couple of minutes thinking about how you would do it differently next time. Worry about seeming like a pushy American.
Repeat, endlessly, on every trip to Spain.