I've spent a fair bit of time working on this same problem and I'll describe the macros I've come up with to help me.
Step 1 - Manual adjustment
My first step in setting a z-offset is to use a feeler gauge to get the nozzle at .2mm (I don't use paper for this, a good set of feeler gauges is less than $10). After doing this, I run my first Macro that adjusts the z offset so that the current tool position is .2mm.
; This macro adjusts the zoffset of the current tool to make the current z value 0.2mm
; optional input is Z = value we want Z to be after changing the z offset
; use case:
var target_z_vale = 0.2
M291 P"This macro will reset the current tool offset to make the current tools Z value 0.2mm." S3 T0
;If no tools is selected, prompt the user
if state.currentTool =-1 ; menas there is no tool selected
M291 P"No tool selected. Select tool first." S1 T0
M99
; Read the current tool offset
var current_Z_offset = tools[state.currentTool].offsets[2]
; read the current z value
var current_z = move.axes[2].machinePosition
; calculate z offset needed to make current Z = 0.2mm
var new_z_offset = 0.2 - var.current_z
; build the command string
var command = "G10 P"^{state.currentTool}^" Z"^{var.new_z_offset}
; Create the replacement for the tooloffset file
echo >{"tool"^state.currentTool^"_Z_offset.g"} {"; This macro sets the Z offset for tool # "^state.currentTool}
echo >>{"tool"^state.currentTool^"_Z_offset.g"} {var.command^" ;changed: "^state.time}
; run the new z_offset file
M98 P{"0:/sys/tool"^state.currentTool^"_Z_offset.g"}
I have a personal peeve about using M500 to store parameters, so I write little macro files. On line 24, you'll see I build the G10 command to set the new z-offset. Then, on lines 28 and 29, I write that command to a file. I also include the date and time the file is created in a comment. Finally, I run that macro (line 33) to set the new z-offset.
And since I have a problem with M501 to restore settings, I have a line in my config.g file to run that macro on startup.
Having the date and time in the macro means I can look at it to verify that a new z-offset really got saved.
Step 2 - folding baby steps into the z-offset
My second step in setting z-offset if to use baby stepping when the first layer is printing to get it dialed in better. This macro is something I run after a print finishes to "roll" those baby steps into the z-offset.
; Macro to
; 1. Read the current babysteps
; 2. Read the Z offset on the current tool
; 3. Create a command to adjust the tool z offset to use zero babysteps
; 4. Overwrite the zoffset file for this tool with the command
; 5. Set baby steps to 0
; 6 Run the new z-offset file
M291 P"This macro will reset the current tool offset incorporate the currently active babysteps." S3 T0
;If no tools is selected, prompt the user
if state.currentTool =-1 ; menas there is no tool selected
M291 P"No tool selected. Select tool first." S1 T0
M99
; Read the current baby steps
var baby_steps = move.axes[2].babystep ; Positive babystep means the bed is farther from the nozzle
; Read the current tool offset
var current_Z_offset = tools[state.currentTool].offsets[2]
; Calculate the new tool offset
var z_offset_new = var.current_Z_offset - var.baby_steps
; build the command string
var command = "G10 P"^{state.currentTool}^" Z"^{var.z_offset_new}
; clear the baby stepping
M290 R0 S0
; Create the replacemetn fro the tooloffset file
echo >{"tool"^state.currentTool^"_Z_offset.g"} {"; This macro sets the Z offset for tool # "^state.currentTool}
echo >>{"tool"^state.currentTool^"_Z_offset.g"} {var.command^" ;changed: "^state.time}
; run the new z_offset file
M98 P{"0:/sys/tool"^state.currentTool^"_Z_offset.g"}
This macro operates similarly to the first one, but makes an adjustment based on the current baby steps. It's important to clear the baby steps (line 30) in addition to changing the z-offset.
If you have multiple tools, and want to adjust z-offsets based on the baby steps differently for each tool, you need to include it in the tool change process. That's another macro and I'll leave it out for now.