Execute Shell Script Action Fails to Increase macOS Contrast

A follow-up on this ...

Providing the full path for this Pandoc command fixed the issue. All good. I made a mental note to remember this next time I need to run a shell script. Today was one such day!

I want to run some shell scripts to change some OS Accessibility settings. An example:

defaults write com.apple.universalaccess increaseContrast -bool true

This command sets increased contrast to on. That works in Terminal, but not in KM. OK, so I shall find out the path using:

which defaults

And that revealed the path as:

/usr/bin/defaults

So, all I need to do is set it like this in KM Shell script, right?

/usr/bin/defaults write com.apple.universalaccess increaseContrast -bool true

But that does not work, I get this error:

2023-02-23 21:50:09 Execute a Shell Script failed with script error: 2023-02-23 21:50:09.226 defaults[47118:10617287] Could not write domain com.apple.universalaccess; exiting. Macro “Increased Contrast Off” cancelled (while executing Execute Shell Script).

So I must need something additional here. I have checked the Shell script page in the KB, but it's really not close to my comfort zone, and I can't work out what I have missed.

As usual, I appreciate all the help that people provide here.

1 Like

Hey @Lloydi,

  • What version of macOS are you using?
  • What version of Keyboard Maestro are you using?

My best guess at the moment is that you have a permissions problem.

See if this runs:

Download Macro(s): Create a File on the Desktop Using an ‘Execute a Shell Script’ Action v1.00.kmmacros (2.1 KB)

Macro-Image

Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2

-Chris

I am using Ventura 13.0 and KM version 10.2.

Also, yes, that macro did work with no issues. Text file created with no bother :slight_smile:

On Mojave when I run:

defaults write com.apple.universalaccess increaseContrast -bool true

I have to quit and restart apps to get them to show the change in contrast.

Yep, that’s expected behaviour. I can handle that issue separately. The issue is that while I can run these commands in Terminal, it won’t work on KM shell script, even when specifying the path.

2023-02-23 21:50:09 Execute a Shell Script failed with script error: 2023-02-23 21:50:09.226 defaults[47118:10617287] Could not write domain com.apple.universalaccess; exiting. Macro “Increased Contrast Off” cancelled (while executing Execute Shell Script).

This may mean that domain is not available on Ventura.

I.e. the command structure has changed.

It's not picking up the "domain" correctly. Try being explicit, with:

/usr/bin/defaults write ~/Library/Preferences/com.apple.universalaccess increaseContrast -bool true
1 Like