I already answered this in a comment, and a couple of people told you that you did differently from the answers, but I decided to add a small code example with error checking:
chdir("/var"); FILE *scriptFile = fopen("wiki.txt", "w"); if( !scriptFile ) { fprintf(stderr, "Error opening file: %s\n", strerror(errno)); exit(-1); } else { fputs("tell application \"Firefox\"\n activate\n",scriptFile); fclose(scriptFile); }
Now you will see an error message if your file is not open, and it will describe why (in your case access is denied). You can do this work for testing: 1) replacing your file name with something worldwide, for example, "/tmp/wiki.txt" ; or 2) running your utility with sudo ./your_command_name privileges.
source share