Ok then it seems is never calling the set_persistent_string_variable for the case were it doesn't work. Most likely the script doesn't find the view count and then bails out via the throw error. You could add some more logs (e.g. log the HTML or the result of your shell script)
I've tried to eliminate issue with the script, by replacing it with simple apple script:
on itemScript(itemUUID)
set currentTime to do shell script "date '+%H:%M:%S'"
-- Set the persistent string variable in BetterTouchTool
tell application "BetterTouchTool"
set_persistent_string_variable "custom_var_test_view_count" to currentTime
end tell
return currentTime
end itemScript
This use-case remains the same - script should run each time "BTTNowPlayingInfoTitle" is changed, but it is not. I've also tested with another variable to be "monitored", but again the same result - HUD is shown, the actual action (applescript) is not being executed.
Ah I see. Unfortunately BTT can't handle this sort of apple script definition. Just remove the "on itemScript(itemUUID)" and "end itemScript". Also remove the function to call
This only works in specific contexts because in a variable value did change context, there is no itemUUID
I'm not sure what happened, but this now works 99% of the time. Thank you for your help @Andreas_Hegenberg .
There's however something which is bugging me - if I configure BTTNowPlayingInfoTitle to be the monitored variable - on pause/play or going into Safari's youtube tab, the trigger is triggered, but if I check the var's value it is still the same. If I use a persistent variable custom_var_test_title set like this (basically having the value of BTTNowPlayingInfoTitle):
set songTitle to get_string_variable "BTTNowPlayingInfoTitle"
set_persistent_string_variable "custom_var_test_title" to songTitle
this does not happen. Just reporting if this is unexpected.