I am working with an electron app and I have a task about disabling the hot corners in Mac with a script. I am quite new in the subject so I am wondering if anyone around have already dealt with a similar situation.
When launching the app, the electron window does not take the full width but it is something we could implement if the hot corners can get to be disabled this way.
Any hints would be appreciated. Thanks
There is no "safe" way of doing this that doesn't run the risk of indefinitely disabling your users' hot corners. If your program crashes or is otherwise terminated unexpectedly, you absolutely should ensure that there is some contingency to reset these keys back to their original values. I would go so far as to say this is absolutely not a recommended approach and that these types of UX-modifying hacks are way less than ideal.
If you must do so, you can probably get away with doing something via node-applescript:
const applescript = require('applescript');
var hotCorners = {
'wvous-bl-corner': null,
'wvous-bl-corner-modifier': null,
'wvous-br-corner': null,
'wvous-br-modifier': null,
'wvous-tl-corner': null,
'wvous-tl-modifier': null,
'wvous-tr-corner': null,
'wvous-tr-modifier': null
}
// read current default values first
Object.keys(hotCorners).forEach(key => hotCorners[key] = applescript.execString(`do shell script "defaults read com.apple.Dock ${key}"`));
// overwrite with zeros to disable hot corner functionality
Object.keys(hotCorners).forEach(key => applescript.execString(`do shell script "defaults write com.apple.Dock ${key} -int 0"`));
And at the point when you wish to write these configurations back:
Object.keys(hotCorners).forEach(key => applescript.execString(`do shell script "defaults write com.apple.Dock ${key} -int ${hotCorners[key] ?? 0}"`));
You should also take care to write the current configuration to a less-ephemeral storage medium than RAM; easiest way to do that would be to write the JSON structure to a file within your Electron app (or to storage elsewhere on the client device).
The success of this method will depend on several factors relating to the macOS version and security posture of the client device and the user themselves (whether they accept any security prompts relating to this functionality in later versions of macOS). As such you should also be implementing error checking with this type of functionality to ensure that you can properly react to unexpected conditions.
In the interest of full disclosure, I no longer have access to a macOS machine to test this on; as such this code is untested and I do not guarantee its success in any capacity - use this guidance at your own peril.