There are two different things potentially stopping this from working the way you describe.
First, -[NSFileManager changeCurrentDirectoryPath:]
may return NO
, indicating that it was unable to change the current directory as requested. This could happen because the path doesn't exist, or is otherwise inaccessible — and on macOS 10.15 Catalina, some paths (like Downloads) may be inaccessible to scripts as a security measure. Your code should check the return value of that method and handle the error case.
Second, even if you're not running Catalina or pick a folder that is accessible, running the compiled program in a shell won't change the current directory in that shell. This is deliberate behavior on the part of bash
and similar shells, as described in several other questions — your call changes the working directory for your process, but that change does not propagate to the parent process. (The last question linked there describes a way to get around this, but its author recommends against using that strategy.)