An intelligent “antimicrobial switch” has been constructed to reduce prolonged exposure of pathogenic bacteria to antibiotics, which could reversibly “turn off” or “turn on” the antimicrobial activity of hemicyanines through self-assembly or dis-assembly of cucurbit[7]uril (CB[7]). This assembly effectively inhibited the production of ROS under light, shielding the active site of hemicyanines and achieving on-demand antimicrobial ability. Moreover, CB[7] differentially inhibits ROS of molecules with different alkyl chain lengths, which provided reference for the subsequent design of materials with antimicrobial activity regulation, and could effectively delay or even prevent the development of pathogens resistance.