1

I am making an app in python on mac osx which needs changes in config.cfg file. I converted the python script into myapp.app by using py2app. I included my config.cfg file in Resources location of myapp.app through setup.py. Then, I used Packages to install myapp.app in /Applications location by making myapp.pkg file. But, when I opened myapp in Application location by Show Package Contents, and tried to edit the config.cfg file, a dialog box comes which says You don't own the file config.cfg and don't have permission to write it. I am using osx 10.8.5 Mountain Lion and Xcode 4.6.1. MY config.cfg file

[FOLDER]
extensions = cfv
#############################

[KMS]
serverIP1 = 127.56.98.104
serverPort1 = 8080
serverIP2 = 172.46.84.145
serverPort2 = 8080
SSL=TRUE
imp
  • 1,967
  • 2
  • 28
  • 40

1 Answers1

1

Don't store modifyable data in the app bundle; everything in that should be static, otherwire permissions will be a mess, code signing will break, etc. In general, user-modifyable files belong in the user's home folder. For a config file, the best thing to do is probably to treat it as a preference file and store it in ~/Library/Preferences. Note that the naming convention for preference files is to use your domain name in reverse order as a prefix before the app name (e.g. com.apple.Finder); if you don't own a domain name, I'd recommend using "local" as a prefix instead. Also, most files in that folder are in .plist format (e.g. com.apple.Finder.plist); your file presumably isn't, so use some more appropriate extension (.cfg would be fine).

Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
  • I appreciate your suggestion sir. How to give config.cfg file to different user. As initially, code have to read a lot of data from config.cfg file for starting the running of app. – imp Oct 28 '13 at 15:56
  • I'm not sure I understand what you're trying to accomplish. In OS X each user generally has their own personal app settings, which they configure and maintain. I suppose you could give someone a copy of your .cfg file with instructions to put it in their ~/Library/Preferences folder... – Gordon Davisson Oct 28 '13 at 16:04
  • Sir, see my config.cfg file, as for running of app, needed serverIP and port. I am passing this in config.cfg file. User need to change this serverIP, according to their server. Also I am using configparser for reading config file. So, are you saying that, I need to make a dmg file which wiil contain, myapp.pkg which will installed in Application location, and config.cfg file which user needs to place it in ~/Library/Preferences folder. Is THERE ANY way to directly place config.cfg file, in ~/Library/Preferences location automatically while installation of app, without user interfeernce. – imp Oct 28 '13 at 17:31
  • What I'd recommend in that case is including a default .cfg file in the app bindle (e.g. in Contents/Resources), and having the app check whether ~/Library/Preferences/local.yourapp.cfg exists and if not copying the default to that location. Note that your app should do this each time it's run, *before* running configparser on ~/Library/Preferences/local.yourapp.cfg. – Gordon Davisson Oct 28 '13 at 19:00