如何在Mac OS上默认使.py文件可执行? [英] How do I make .py files executable by default on mac OS?
问题描述
我知道您可以执行"chmod + x filename.py"以使文件在Mac上可执行,但是有没有办法我可以更改某些设置,以便在创建扩展名为.py的文件名时默认发生这种情况?
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?
推荐答案
我不确定这是多么明智的想法,但是您可以使用文件系统监视程序" (例如> fswatch
(等同于Linux的 inotifywait
的macOS).
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
).
因此,您可以像这样使用自制软件安装 fswatch
:
So, you can use homebrew to install fswatch
like this:
brew install fswatch
然后,假设您想监视 HOME
目录下与Python文件有关并涉及文件创建的所有文件系统事件,可以运行:
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
您将看不到任何内容,但是一旦创建以 .py
结尾的文件,它将在该文件上运行 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.
这篇关于如何在Mac OS上默认使.py文件可执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!