Sorry, I should have been more clear, I meant at runtime, 'Just-In-Time', maintaining the context of the selected object.
All that script does it update the global definition of the Custom Command which, whilst useful, will fail to provide custom list items based on the contextual object.