Easiest is just to write code in the command window and middle drag it to the shelf maya will then create a button for you, (you can then use shelf editor to assign it with a icon, its the arrow down next to shelf)
toggling xray, ha been asked a 10 times this year alone times times and the simple answer is drag following code to the shelf:
modelEditor -e -xr (!modelEditor("-q","-xr",getPanel -wf
)) getPanel -wf
;
read it turn modelPanel with focus xray mode into what its not.
I suggest you do use shelf for this kind of stuff as thats what its intended for, this saves a lot of space too because having one extra window is just extra clutter. And then you dont need to bother reloading some extra windowing stuff.
PS Those of us that don't know how to script will not find yours and those that do can easily enough whip their own user environments, or better yet reorganize the maya internal gui seamlessly (such as putting the code inside the tollbox, or add in channel box component)
Most users have populated 10 to 30 shelves of stuff over the years as its not so hard. In fact i have never seen a single professional maya user who would have had exactly the same maya GUI as the person sitting next to him. And yes most animators I know, do know how to script, they dont do it so osften but they know how it works (when they cant do it they know where to ask, its the TD down the hall).