Sublime Forum

Add ability to overwrite all write-protected files

#1

Hi !

In case when you tries to overwrite a lot of write-protected files, Sublime Text 3 shows dialog “Overwrite write-procected file << path >>” with two options: Overwrite and Cancel. This dialog appears on each file.

Could you please:

  1. Add button “Overwrite all” to avoid mouse button clicking
  2. Add ability configure sublime to overwrite file without this dialog (e.g. sublime will uncheck this flag without any questions)

?

In addition: after you decision, could you please answer here on stackoverflow ?

0 Likes

#2

for 2., you might be able to write a plugin that listens for the on_pre_save event and unmarks the file as write protected

0 Likes

#3

Based on @kingkeith’s idea I wrote a small plugin that seems to work on macOS:

import sublime_plugin
import os
import stat

class MakeWritableIfNot(sublime_plugin.EventListener):

    def on_pre_save(self, view):
        if not view:
            return
        file_name = view.file_name()
        if not file_name:
            return
        if os.access(file_name, os.W_OK):
            # File is writable; just return
            return
        st = os.stat(file_name)
        os.chmod(file_name, st.st_mode | stat.S_IWUSR)

Save this as MakeWritableIfNot.py in sublime’s User directory.

1 Like

New files saved without executable permissions