'重启Apache'AppleScript

以下是您在Mac上开发网站的快速提示。

When you make changes to Apache’s configuration file (/etc/httpd/httpd.conf), you need to restart Apache to get the changes to take effectMy most frequent need for this is when I set up new staging servers using virtual hosting, but it’s the case for any change you make to httpd.conf.

Apple’s built-in way to restart Apache is the use the Personal Web Sharing section of the Sharing panel in System PreferencesJust click Stop and then click StartEasy — but it’s only really convenient if you’ve already got the Sharing prefs panel open.

从终端,您可以使用。重启Apacheapachectl gracefulcommand, which requires administrator privileges, which means you’d typically invoke it assudo apachectl优雅That’s easy too, but, again, is only convenient if you’ve already got a terminal window open and can remember the exact spelling of ‘apachectl’.

因为我真的很懒,所以我制作了一个AppleScript来做到这一点It’s just one single line:

使用管理员权限执行shell脚本“apachectl graceful”

我把它保存为一个名为“Restart Apache”的编译脚本/图书馆/脚本folder in my home folder, which puts it in my system-wide Scripts menu(You can turn the system-wide Scripts menu on using the AppleScript Utility app in your/程序/ AppleScript夹。)

So it’s as simple as this: when I need to restart Apache, I choose “Restart Apache” from my system-wide Scripts menu, the script prompts me to authenticate with admin credentials, and that’s it.

更新: Shane Becker演示了如何添加键盘快捷键to the ‘Restart Apache’ script menu item.