If I understand your intention correctly I don’t believe the ability to identify which collections are selected in the outliner is exposed to the API but instead are part of the source code.
My interpretation of your intention is to identify:
Both the collection named ‘Objects’ and ‘Reference Images’ are to be affected and no other collection within the “Scene Collection” viewlayer.
As a hacky work around to an issue like this one possibility would be to perform a specific operation from the outliner context like bpy.ops.outliner.collection_color_tag_set(color='COLOR_01')
Then you could make a list of the collections within the viewlayer that specifically have that property set to iterate over. Similar to:
import bpy
C = bpy.context
D = bpy.data
def recurLayerCollection(layerColl, collName):
found = None
if (layerColl.name == collName):
return layerColl
for layer in layerColl.children:
found = recurLayerCollection(layer, collName)
if found:
return found
layer_collection = C.view_layer.layer_collection
coll_names = []
for coll in layer_collection.collection.children_recursive:
if not coll.color_tag == 'COLOR_01':
continue
coll_names.append(coll.name)
print(coll_names)
At which point you could create a for loop to perform all your operations based on the names in the list coll_names and finally set the color tag property back.