Got errors when changing a readonly file (the CSS of pop-out dictionary) on OS X

Solution 1:

You're attempting to edit a file within a restricted location, protected by System Integrity Protection.

$ ls -O /System/Library/Assets/com_apple_MobileAsset_DictionaryServices_dictionaryOSX
total 104
drwxr-xr-x   7 root  wheel  restricted  224B 19 Apr 09:29 ./
drwxr-xr-x@ 24 root  wheel  restricted  768B 31 Mar 12:15 ../
drwxr-xr-x   5 root  wheel  restricted  160B 31 Mar 12:19 2fcc349eb53d7c336b8372758b70508eb8e2ac0b.asset/
drwxr-xr-x   5 root  wheel  restricted  160B 31 Mar 12:19 61b49f47f0dce1c061c688d415e1f1a84c37fce0.asset/
drwxr-xr-x   5 root  wheel  restricted  160B 31 Mar 12:19 cd4d7cc1cd227a13d2b9c029f86c940f94b7543a.asset/
-rw-r--r--   1 root  wheel  restricted  3.4K 19 Apr 09:29 com_apple_MobileAsset_DictionaryServices_dictionaryOSX.plist
-rw-r--r--   1 root  wheel  restricted   44K 19 Apr 09:29 com_apple_MobileAsset_DictionaryServices_dictionaryOSX.xml

These cannot be edited even with sudo. To edit files within restricted locations, either:

  • Perform the edit from Recovery HD.

    1. Boot into the Recovery HD by restarting whilst holding ⌘R.
    2. Use the Terminal from the Utilities menu in Recovery to perform the edit. Note that / is the mount point of the recovery environment, therefore you should access your disk from /Volumes/yourdiskname/….
    3. Reboot
  • Disable System Integrity Protection, perform the edit, then re-enable it.

    1. Boot into the Recovery HD by restarting whilst holding ⌘R.

    2. Open Terminal (from the Utilities menu).

    3. Run the following command in Terminal:

       csrutil disable
      
    4. Restart.

    1. Perform the edit you wish to make to the files.

    2. Boot into Recovery HD once more and run csrutil enable to re-enable SIP.