I am running a JXA script as an agent using launchctl. The main logic of the script is supposed to be run at intervals of 2 seconds, which I have achieved using
launchctl