on doToEachButton whatToDo,options  
  if options is not "bkgndOnly" then
    repeat with i = 1 to the number of buttons
      send whatToDo to button i
    end repeat
  end  if
  if options is not "cardOnly" then
    repeat with i = 1 to the number of bkgnd buttons
      send whatToDo to bkgnd button i
    end repeat
  end if
end doToEachButton
This article is adapted from the Claris Tech Info database.