Can't Figure Out Error: Read-Only File System. Macro Cancelled

I'm new to KM and could use some help with my first macro.

My macro is set up to execute a shell script with input from nothing. Here's the text script that KM is executing:
sh "/Users/MyUserName/Dropbox/Folder/test.sh"

The script is pretty straightforward:
1 #! /bin/bash
2
3 echo "Hello!" > test_output.txt

I can run this script successfully from my terminal.

However, I get an error like this when I execute the KM macro:
2020-08-04 08:56:09 Execute a Shell Script failed with script error: /Users/MyUserName/Dropbox/Folder/test.sh: line 3: test_output.txt: Read-only file system. Macro “MyMacro” cancelled (while executing Execute Shell Script).

I have a very similar error pattern. Did you ever figure this out?

Have you granted all the privileges it requires such as "Full Disk Access"?

I just tried granting Keyboard Maestro full disk access. That did not resolve the issue. :frowning:

When you say you can run it in Terminal do you mean the command line itself or the script file? If the latter did you make sure it's executable? To make it the one permissions must be -rwxr--r-- (executable by you, the current user).

Probably worth specifying the output folder.

It may, by default, be trying to write to the device root.

This, for example, is working fine here:

image

and this:

image

Reveals that until you specify the output folder, the default is indeed the system root, to which, if all is well, you will have no write access:

2 Likes

Did you find any solution? I have the exact same issue [Errno 30] Read-only file system. I also have KM access to all permissions. Not many other threads out there to look for solutions...

Hey @adenosine,

Welcome to the forum!   :smile:

See Post #6 above.

-Chris

Hi @ccstone I am facing this issue but unable to figure out what exactly is Post #6 above?

Please consider showing your macro, which is giving you a problem.

My macro is very simple. It execute a python script.
BASE_PATH/env/bin/python3 BASE_PATH/km/rename_image.py

However the logic where it writes to a log file is failing giving error
Warning: Could not write to log file: [Errno 30] Read-only file system:

I'm no script expert, but I can't see how your script can work, since you are missing "$" characters before each shell variable. Also, you have to tell us the contents of your variable "BASE_PATH" or we won't be able to give much advice. Also, depending on the contents of the BASE_PATH variable, you may need double quotes around it, but since I don't know what it contains, I can't be sure.

I was hoping one of the super-wizards would have answered you, but since they haven't, I gave it a shot. My advice is sometimes imperfect.

Run this from Terminal:

bash

touch /actual/path/to/logfile.log

If you get a "Read-only file system" error, you’ve found the issue. That directory (or disk) is mounted as read-only — could be due to:

  • External drive or network share mounted read-only
  • System integrity protections (especially on macOS)
  • Running in a sandboxed environment (like some automation tools or mounted containers)

Here is the complete script. I used /Users/horcrux2301/Local-Docs/env/bin/python3 /Users/horcrux2301/Local-Docs/dotfiles/km/anki_close_adv_uri_link.py.

The script executes successfully. But only the logic to write to a log file is failing when executing from KM. It works perfectly when executed directly from terminal.

I was hoping one of the super-wizards would have answered you, but since they haven't, I gave it a shot. My advice is sometimes imperfect.

Thank you for taking out the time to answer my query. Your messages are helpful. :slight_smile:

The script executes successfully. But only the logic to write to a log file is failing when executing from KM. It works perfectly when executed directly from terminal.

Can you upload the action that is failing? Just a wild guess but probably something that needs to be selected in the left in the disclosure triange to "enable modern syntax."

The original script fails because it never specifies what the current directory should be so the attempt to write to test_output.txt is writing to an unknown location, which apparently is not writable.

Scripts should not generally write a file to somewhere without knowing where it will write, so the script should either specify the full path of the file to write to, or use a cd to change to a known safe location, or otherwise specify the file path fully.

It''s odd that it works outside of Keyboard Maestro but only fails in Keyboard Maestro.

In Terminal, the write portion of a command will simply write to the current directory, if no path is specified. Given you're probably in a directory you can write to, the command works. Keyboard Maestro has no idea about a current directory, as it's just executing a command.

-rob.

1 Like

Why is it odd? The current working directory is different.

It'll fail outside Keyboard Maestro too if you cd to a readonly file system.

In the OP, if you do this in the Terminal:

cd /System
sh "/Users/MyUserName/Dropbox/Folder/test.sh"

it will fail the same way.