问题
I have created an osx app that runs perfectly in Xcode but not from Finder window. It reads a binary data file and outputs two simple text files and displays some graphics. Since it works in Xcode, I copy the app file to say Applications directory along with the binary input file. The binary file can be read okay. The two text files cannot be opened for writing (permission denied) and so the program exits. When run from Xcode, there is no problem writing the two text files in the Applications directory.
I have checked the permissions for the text files and they are read/write for my username and group (staff) both from unix terminal ls -al and Finder get info.
So it appears that the app cannot open any file for writing in the Applications directory when double clicked from Finder window.
I have tried several directory locations for the app and the binary input file without success.
/Users/person/Library/Application Support/MyApp /Users/person/Applications/MyApp
None work when started from Finder, but all work from Xcode.
The working directory is / when started from Finder, but the program changes it at startup to the appropriate directory.
This problem has got me beat. I’ve run out of ideas. Any help would be appreciated.
回答1:
Full path names resolves all issues with running from Finder. Multiple directory locations were tried successfully. Awesome thanks to Paul R.
来源:https://stackoverflow.com/questions/26149445/app-wont-write-to-file-when-run-from-finder-ok-in-xcode