简体   繁体   English

如何在Mac OS上默认使.py文件可执行?

[英]How do I make .py files executable by default on mac OS?

我知道您可以执行“ chmod + x filename.py”使文件在Mac上可执行,但是有没有办法我可以更改某些设置,以便在创建扩展名为.py的文件名时默认发生这种情况?

使用Automator,创建一个运行可运行python的shell脚本的应用程序,并设置用于打开.py文件的默认应用程序。

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 (与macOS等效于Linux的inotifywait )。

So, you can use homebrew to install fswatch like this: 因此,您可以像这样使用homebrew安装fswatch

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: 然后,假设您要监视HOME目录下与Python文件有关并涉及文件创建的所有文件系统事件,可以运行:

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. 您什么都看不到,但是一旦创建了一个以.py结尾的文件,它将在该文件上运行chmod +x使其可执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM