How do I detect when a shulker box is opened?

So basically, I want to create a way to detect when a shulker box is opened, using commands. I've searched everywhere on the internet on how to do so, and I can't find an answer.


You first should add a scoreboard that increases whenever you open a shulker, you can do so like this:

scoreboard objectives add shulker minecraft.custom:minecraft.open_shulker_box

Then, in a repeating command block, or in a tick.mcfunction file, you can put this:

execute as @a[scores={shulker=1..}] at @s run (your command)

And now, so the command only executes once, you can do (also in a repeating command block/tick.mcfunction file):

scoreboard players reset @a[scores={shulker=1..}] shulker

scoreboard objectives add opened_shulker minecraft.custom:minecraft.open_shulker_box

All players who open a shulker box will have 1 added to their score.