You can use a filter. I made a script very similar to this which also alches the looted nats. Heres an example using filters, although i prefer to use lambas rather than the traditional way of filtering:
chest = getObjects().closest(o -> o.getPosition().equals(new Position(2671, 3301, 1))); // filters out every entity that's not at the specified position (ie. chest 2)
if(chest.interact("Search for traps")){
log("Attempting to loot chest...");
new ConditionalSleep(15500, 17550){
@Override
public boolean condition() throws InterruptedException {
int start = getSkills().getExperience(Skill.THIEVING);
return ((getSkills().getExperience(Skill.THIEVING) > start) || wasLooted);
}
}.sleep();
// I have a method that wasLooted that uses game messages to see if its already looted and then the wait time is adjusted accordingly