This is a modification of Assigning keyboard key to Python script in ArcMap?
I want to assign a shortcut key to call custom Python script while editing vector layer in ArcGIS 10.3. The rationale behind Python script that called by shortcut is to minimize steps required to turn on/off particular layers in the Table of contents. The answer provided in the initial question does not solve the problem.
'''
Script turns off A & B layers.
'''
import arcpy
#A list of layer names that needs to be turned off.
names = ["A", "B"]
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
layers = arcpy.mapping.ListLayers(mxd, "*", df)
for layer in layers:
if layer.name in names:
layer.visible = False
arcpy.RefreshTOC()
arcpy.RefreshActiveView()