We present a method to generate high-energy flat-top UV laser pulses such as the ones needed to optimally drive high-brightness radio-frequency photoinjectors. In this scheme we believe to be novel, the longitudinal profile of a laser pulse from a Ti:sapphire master oscillator power amplifier system is controlled using a mechanical mask in the Fourier plane of a 4f stretcher located after the harmonic conversion crystals. Such a scheme allows us to overcome many of the difficulties faced by current state-of-the-art pulse-shaping designs. These are in fact based on various versions of preamplifier infrared shapers and hence suffer from the limitations set by the nonlinearities of chirped-pulse amplification and harmonic conversion. Beyond the clear advantages of simplicity and robustness, the proposed solution offers the possibility to deliver a pulse with very short rise and fall times and to freely change the output pulse length. We also note that, after proper calibration between spectral and temporal profiles, the shaper optical setup offers the possibility to retrieve the longitudinal profile of the laser pulse on a shot-to-shot basis.