Mapping keyboard with xmodmap and xcape on startup

This works great when I do it in terminal, but I keep getting issues when I try to automate it on startup. I’ve added modifications to the .Xmodmap file and I run xcape scripts in .xprofile. Should I be doing this differently?

My .Xmodmap

keycode 248 = Tab
keycode 23 = ISO_Level3_Shift

(I’m mapping Tab to an undefined key and AltGr to Tab)

My .xpofile

#!/bin/bash
xcape -e 'Control_L=BackSpace'
xcape -e 'ISO_Level3_Shift=Tab'

(Control becomes backspace when tapped, and AltGr (Tab) becomes Tab when tapped)

The issue is that when I run it on startup, it doesn’t recognize xcape -e 'ISO_Level3_Shift=Tab' and I can’t use Tab on my keyboard. Previously I had put the entire thing as a Desktop entry, but I had a different issue: the AltGr wouldn’t work on startup. What’s the proper way to do a startup script so that I can modify my keyboard without issues? Sorry, I’m new at Linux.

Thanks empty forum.

In the end I just created my own shortcut to run .Xmodmap and xcape commands on the command line, kind of like initiating a custom keyboard with a shortcut. KDE makes it easy to create custom shortcuts, but I think it can be done manually too.

I never did figure out a way to run both xcape and xmodmap at the same time without conflicts on startup. I’m guessing xinitrc might have something to do with it? But my workaround is good enough for now.