切换Web共享 [英] Toggle Web Sharing
问题描述
我在寻找一个AppleScript切换雪豹Web共享。 我想这但并不禁止,只是重新启动它,当我再次运行。或shell命令,只要我可以把它变成一个水银行动。这是我的最终目标。非常感谢!
I'm looking for an Applescript to toggle Web Sharing in Snow Leopard. I tried this but it doesn't disable, just restarts it when I run it again. Or a shell command as long as I can turn it into a Quicksilver action. That's my end goal. Thanks so much!
推荐答案
您可以使用下面的shell脚本来切换在Mac OS X服务的启用状态:
You can use the following shell script to toggle the enabled state of a Mac OS X service:
#!/bin/sh
# toggle OS X service
if [ "$#" -ne "1" ]
then
echo 1>&2 Usage: `basename $0` service
echo 1>&2 Toggle the enabled state of the given service.
exit 2
fi
SERVICE_NAME=$1
SERVICE_PLIST=/System/Library/LaunchDaemons/$SERVICE_NAME.plist
if [ ! -f "$SERVICE_PLIST" ]
then
echo 1>&2 Service $SERVICE_NAME is not available.
exit 1
fi
/sbin/service --test-if-configured-on "$SERVICE_NAME"
if [ $? -eq 0 ]
then
/bin/launchctl unload -w "$SERVICE_PLIST"
else
/bin/launchctl load -w "$SERVICE_PLIST"
fi
该脚本使用服务命令来确定服务,然后通过调用切换它的状态 launchctl 。
The script uses the service command to determine if the service is on and then toggles its state by invoking launchctl.
该服务的名称已对传递作为唯一的参数。要切换网络共享运行:
The name of the service has to passed as the only argument. To toggle web sharing run:
sudo toggle_service.sh org.apache.httpd
要通过的AppleScript调用shell脚本可以使用做shell脚本命令:
To invoke the shell script via AppleScript you can use the do shell script command:
do shell script "toggle_service.sh org.apache.httpd" password "pwd" with administrator privileges
使用密码
参数,以避免被提示。
这篇关于切换Web共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!