So this is an old post, but saw it as I was googling and thought I could answer anyway.
I’m not sure if there’s a way to get the shelf tab index directly from the tab name, but this should work:
Bear in mind, the tab label may not be what the actual shelf is named since Maya make a nice name of “MotionGraphics” to “Motion Graphics” in the UI. Just make sure to type in the name as the shelf is called. For convenience I always use underscore in my names for this purpose.
shelf = 'MotionGraphics'
# set this int to where you want to move the tab to. It starts at 1
moveTo = 1
# select the tab by label
mc.tabLayout(gShelfTopLevel, e=True, st=shelf)
# get the index of the selected tab
currentTabInt = mc.tabLayout(gShelfTopLevel, q=True, sti=True)
# Move the tab to its new position
mc.tabLayout(gShelfTopLevel, e=True, mt=(currentTabInt, moveTo))
# set focus back to the tab
mc.tabLayout(gShelfTopLevel, e=True, sti=moveTo)