切换网络共享

发布于 2024-09-18 17:15:30 字数 220 浏览 2 评论 0原文

我正在寻找一个 Applescript 来切换 Snow Leopard 中的网络共享。 我尝试了这个,但它没有禁用,只是在我再次运行它时重新启动它。或者是 shell 命令只要我能把它变成 Quicksilver 动作就可以了。这就是我的最终目标。非常感谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

就是爱搞怪 2024-09-25 17:15:30

您可以使用以下 shell 脚本来切换 Mac OS X 服务的启用状态:

#!/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

该脚本使用 service 命令来确定服务是否已打开,然后通过调用 启动ctl

服务的名称必须作为唯一的参数传递。要切换 Web 共享运行:

sudo toggle_service.sh org.apache.httpd

要通过 AppleScript 调用 shell 脚本,您可以使用 do shell script 命令:

do shell script "toggle_service.sh org.apache.httpd" password "pwd" with administrator privileges

使用 password 参数以避免出现提示。

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

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

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

Use the password parameter to avoid being prompted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文