0

I know that you can do "chmod +x filename.py" to make the file executable on mac but is there a way I can change some setting so that happens by default when I create a filename with .py extension?

Bhavik Shah
  • 315
  • 1
  • 2
  • 7
  • See this stackoverflow which covers the same question: https://stackoverflow.com/questions/36564320/how-to-make-python-script-executable-on-osx – SteveB Dec 26 '17 at 02:36
  • Thank you SteveB but that thread's answer still asks you to run chmod +x command where as I want to find a way so that MacOS automatically assigns the +x bit to any *.py file right from creation. – Bhavik Shah Dec 26 '17 at 02:41
  • 1
    You can have the whole folder to be executable. – user1767754 Dec 26 '17 at 02:43
  • @user1767754 Thank you. That's a great workaround. I know windows has a way to set default but this takes care of my problem for now. – Bhavik Shah Dec 26 '17 at 02:54

2 Answers2

0

using Automator, create an application that runs a shell script that runs python, and set the default application for opening .py files.

Camden
  • 283
  • 2
  • 15
0

I am not sure how sensible an idea this is, but you can achieve it using a "filesystem watcher" such as fswatch (the macOS equivalent of Linux's inotifywait).

So, you can use homebrew to install fswatch like this:

brew install fswatch

Then, say you wanted to monitor all filesystem events under your HOME directory that pertain to Python files and involve file creation, you could run:

fswatch -0 -E --event Created -e ".*" -i ".py$" $HOME | xargs -0 -n1 chmod +x 

You won't see anything, but as soon as you create a file ending in .py, it will run chmod +x on that file to make it executable.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432