For undulator hard X-ray beamlines of a wide energy range, the beam intensity control is often needed to regulate the photon flux impinging on delicate detectors. Despite the capability of state-of-the-art X-ray pixel detectors being greatly advanced recently, the frontier undulator beamlines in synchrotron facilities often carry outstanding photon fluxes that are sometimes too high for certain measurements. Here, we report a developed protocol that allows intensity attenuation of an X-ray beam in the 4-23 keV energy range with flexible attenuation factors; a prototype is installed and tested on the 13A biological small-angle X-ray scattering beamline of the 3 GeV Taiwan Photon Source (TPS) of the National Synchrotron Radiation Research Center, Hsinchu, Taiwan. The intensity attenuation system is modified from a commercially available pneumatically actuated, vacuum-type precision X-ray attenuator of ADC ABS-300; the system provides beam attenuation factors covering 8 orders of intensity attenuation for an X-ray beam in 4-23 keV. This was achieved with selected combinations of 10 sets of metal foils comprising different thicknesses of Al, Ti, Cu, and Ta foils. A user-friendly protocol is established to automatically compare a subscribed attenuation factor with all the possible attenuation factors from the 1024 combinations of the 10 sets of foils in the X-ray energy used, and determine a set of the metal foils having a best-matched attenuation factor. Calculation of beam intensity attenuations with the selected foils is coded with Python and integrated into the Experimental Physics and Industrial Control System (EPICS). The input of an attenuation factor is done through a graphical display of the attenuator system based on the Control System Studio (CSS). The developed X-ray beam attenuation system provides a convenient and intuitive beam intensity control and has the potential to be adopted in future beamlines.