Move pivot to bottom or top of object/selection Sorry if this has been asked many times but I couldnt find the answer that I was looking for.

Coming from Max I used to have scripts that would place the pivot to the left, right, top or bottom of an object by the push of a button. Now im trying to create something similar in blender python but I cant for the life of me figure out how it works. 

I've searched online but the answers are all pretty confusing and most of them are written for versions earlier than 2.8. 

However I found a script that should place the pivot on the bottom of an object AND doesn't throw an error. BUT actually it doesn't do anything at all either. So i'm wondering why this script won't work for me? 

import bpy
context = bpy.context

for obj in context.selected_objects:
    mx = obj.matrix_world
    minz = min((mx @ v.co)[2] for v in obj.data.vertices)
    mx.translation.z -= minz


The pivot remains in the center of the object.
If you need to move the origin to the bottom, you would need to move it down by the distance it is higher than the lowest point, so you could do: 

import bpy
from mathutils import Vector

o = bpy.context.object
d = o.data
m = o.matrix_world

lowest = min((m @ v.co)[2] for v in d.vertices)
difference = Vector((0,0,o.location.z - lowest))
local_difference = difference @ m
for v in d.vertices:
    v.co += local_difference
m.translation -= difference