Detecting the location of a block through advancements

Is it possible to dynamically detect the location of a block when it has been used? for example, if i open a barrel, can i know its coordinates and run a command on that location?
Continue to help post