Testing for items being held by cursor
Solution 1:
The item held in the cursor is not saved to NBT, but it's still a part of the player's inventory, so /clear
can find it. If you want the same chat spam while cursor-holding the item, throw out the slow NBT method altogether and do this:
/execute as @a store result score @s book run clear @s writable_book{pages:[""]} 0
Of course, you will need to add a scoreboard objective for this (book
in this example). When a player's book
score is 1, that player has a book in their inventory or cursor. This will not work in creative mode, but will in survival/adventure.
If you want something different to happen when you click on the book, you can take advantage of this NBT vs clear disparity. Just add this command in addition to the one above:
/scoreboard players set @a[scores={book=1},nbt={Inventory:[{tag:{pages:[""]}}]}] book 2
Now a score of 0 means no book, a score of 1 means the book is in the cursor, and a score of 2 means the book is in an inventory slot.