A machine tool has a spindle rotating in a headstock and has, further, a gripper for transferring a toolholder from an uncoupled position into a ready-to-couple position within the spindle. A coupling mechanism is provided for further transferring the toolholder from the ready-to-couple position to a couple position within the spindle in which the toolholder can be rigidly connected to the spindle for rotation therewith. In order to control the transferring steps, a sensor is provided for detecting whether the toolholder is in its couple position.