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).
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).
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...
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.
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.
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.
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.