Set scale factor depending on monitors/resolutions upon launching

I’m running Atom on a MacBook Pro (10.15), and I’d like to set the “scale factor” automatically based on whether or not I’m using the built-in display or my external 4K monitor. I’m somewhat familiar with shell scripting, and I realize that I can run, for instance:

sed -i 's/1/0\.8/g' ~/.atom/atom-scale-factor.json

to change the scale factor from 1 to 0.8, and I’m familiar with (again, for instance) a Homebrew package called ‘screenresolution’ from which I can parse whether or not I am connected to said display, but I’d like to know what the best way to go about implementing these settings upon launching Atom would be, whether or not it involves these methods. Any help would be greatly appreciated.