Search code examples
xcodexcode4.6readonly

Can I make an Xcode project read only, ie prevent it from modifying files?


I'm working on an iOS project that I edit in Emacs but debug in Xcode. I occasionally edit the source files in Xcode accidentally, so I'd like to prevent that. I can't make the files themselves read only, since I need to edit them. Is there any way to make the Xcode editor treat them as read only and prevent me from editing them?

I do occasionally use Xcode to edit the project, e.g. adding and removing files. It's just Xcode's file editor that i want to prevent from editing files. So, I'd need something that applies to the file editor only, or that can be easily toggled on and off.


Solution

  • You could give the source folder readonly permissions for your GUI login user and read-write permissions for some other user you just use for terminal/emacs sessions.


    Edit:

    Comments:

    i use my emacs to do lots of other things that i want to keep doing as my normal user, though. i also occasionally do want Xcode to edit the project, e.g. adding and removing files. it's just Xcode's file editor that i want to prevent from editing files.

    Okay then lets flip my solution: Run Xcode as a different user that only has readonly access:

    !#/bin/bash
    su readonlyuser
    /Applications/Xcode.app/Contents/MacOS/Xcode
    

    And then use emacs from your normal session. If you need Xcode to have readwrite access you'll need to quit it and re-open it normally. It's a pain but I can't think of any way around it besides some sort of nifty menu bar app that toggles the permissions on the folder to give your readonlyuser write access. You should also give the readonlyuser readwrite access to the xcodeproj bundle and any other Xcode project metadata.

    To make this a little less ugly you could wrap that bash script in an AppleScript or Automator Action, export it as an application, and give it the same icon as Xcode but with a little indicator so you know it's the readonlyuser one. Then you can stick it in your dock or whatever.