2

Okay, I have thought before asking this question because at first it does sound like the age old question that boils down to "is it possible to write inside of an archive". I am new to Mac OS X but I have read that applications are just a folder with the .app extension and a specific file structure. So, I would like to know if it is possible to write inside of this folder, and if so how.

The reason I ask is because in my Java program, on windows, it reads some files that are in the programs directory (the principle of Program Files) but on OSX applications don't seem to create any files (that are apparent) - so I guessed that they must store them in the .app folder! If I assumed wrong though, I'd like to know where applications normally store the files that they create please.

Thanks in advance

EDIT The whole reason I ask this question is because I fear negative feedback if my application leaves files behind, so really I need informative opinions. In short, my application needs a configuration file, but it also allows users to create their own 'databases'. I now think that I will store these in the user's document folder, but I'm not sure as to whether I should delete these files when the app is deleted or just leave them. Obviously, deleting them would require me to make a package - which would just be an extra step for the user, so what do you think?... Oh yes, and the applications generates a license file upon the user entering a valid serial key - on Windows the information is stored in the registry, but on Mac I am not sure where to put the file containing this information! Any help would be much appreciated.

Andy
  • 3,600
  • 12
  • 53
  • 84

2 Answers2

4

You shouldn't write to the app bundle. Some reasons in no particular order:

  • The user may not have permissions to write to it. In fact, the app bundle can be on read-only media.

  • The app bundle is not specific to the user. It is likely to be in a shared location and used by all the users on the system.

  • Apps should be codesigned and modifying their internals is likely to invalidate the signature.

The appropriate place to put user data is either in the user's Documents folder, in a product-specific subdirectory of ~/Library/Application Support (or, if it should be system-wide, /Library/Application Support), or in a location that the user chooses.

I wouldn't be too concerned about leaving files behind if the user removes the app. It's pretty common and even desirable. For example, if I delete the old version before installing the new version, I want the new version to find the existing files left over from the old version. If you follow typical conventions, the user will know how to clean up (or something like AppZapper will be able to do so for them).

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Thank you so much for this answer - it it just what I needed. I had read that you shouldn't write to the `.app` folder due to permissions, but the other points are useful to know! I've decided that I'm going to store the configuration and licence file in `~/Library/Application Support` and let the decide where to store databases. Thanks for the reassurance on leaving files behind though, I'd read that on Mac it doesn't really matter (in this context) but it just doesn't seem right somehow! – Andy Apr 15 '12 at 10:25
2

I am searching the answer for this question by myself but I think I can help you with your problem. I have ported a "windows" java application by myself. I am no real Mac expert but my research on this topic gave me the following answers:

I understand the *.app folder as the installation package of your program. The internals of this folder are not shown to the user. For him it is simply the app. A quick google search gave me the following hints:

http://developer.apple.com/library/mac/#qa/qa1170/_index.html

where to put application data and temp files on mac

maybe this helps

Community
  • 1
  • 1
  • Thanks for your answer. I actually found the former link myself, and I also found the following link which is somewhat helpful: http://stackoverflow.com/questions/193474/how-to-create-an-ini-file-to-store-some-settings-in-java. What I'm gathering is that it is not advised to store any such files with the application due to various reasons (including permissions) and that instead the Preferences API is commonly used. Though, in response to your comment about the `.app` folder, as far as I can see, users with adequate permissions can explore the contents by clicking "Show package contents"... – Andy Apr 13 '12 at 13:16
  • Anyway, the reason I'm asking this question is because I'm fighting a double edged blade. I'm not to keen on creating an 'installer' for my Mac application, but at the same time I fear negative feedback if my software leaves files in the Preferences. I'm not to sure what to do now. What do you think? – Andy Apr 13 '12 at 13:20
  • Thank you for your answer again. I really appreciate it and I have upvoted you. However, I think the more complete and informative answer is the one of accepted (obviously) - sorry. I wish you luck in the future with regards to porting windows to mac. – Andy Apr 16 '12 at 18:27