0

我需要用自动机启动和停止一台小型服务器,但我的知识非常有限。我无法设置文件所在的路径,也不知道如何停止服务器。

到目前为止,我有这个:

运行中

set r to display dialog "Start or stop the NINJAM server ?" buttons {"Stop", "Start"}

if button returned of r is "Start" then

    #tell application "Terminal"
    #   activate

    do shell script "cd \"/Applications/ MUSIC/ Utilities/Audio IP/NINJAM/NINJAM/NinjamOSXServer ./ninjamsrv Server.cfg\""

    #end tell
else

    do shell script "Stop"

end if

结束运行

任何帮助都非常感谢。提前致谢。

4

1 回答 1

0

请注意,我在这里使用自己的路径——我将 ninjam 服务器文件夹放在了我的应用程序文件夹的顶层。我必须创建一个“术语”文件,这是一个包含以下内容的文本文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>WindowSettings</key>
    <array>
        <dict>
            <key>ExecutionString</key>
            <string>cd /Applications/NinjamOSXServer/;./ninjamsrv config.cfg</string>
        </dict>
    </array>
</dict>
</plist>

我将它保存为 LaunchNinjamSrvr.term 并将其放在与 ninjamsrvr 相同的文件夹中。然后使用的脚本是:

set r to display dialog "Start or stop the NINJAM server ?" buttons {"Stop", "Start"}

if button returned of r is "Start" then
    do shell script "open /Applications/NinjamOSXServer/LaunchNinjamSrvr.term"
else
    do shell script "killall -INT -v ninjamsrv"
end if

[发生在我身上,我应该给出一些解释。直接使用带有“config.cfg”参数的完整路径会使“do shell script”窒息。拆分成两个命令(但仍使用 do shell 脚本),就像您在 .term 文件中看到的那样,可以启动 ninjamsrv,但会使脚本编辑器(我使用 Smile)冻结。这就是(大概——我不想通过其他方式测试它[脚本应用程序等])一个问题,也是我求助于使用 .term 文件的原因。过去,您可以从终端的“文件”菜单(我记得)直接保存一个 .term 文件,但这似乎已经被搁置了。所以,在这一点上,我有一个我使用的模板,只需将命令粘贴到适当的行中。(但请参阅http://discussions.apple.com/thread/3139585?start=0&tstart=0-- 其中解释了导出终端首选项文件的技术)。我有点懒惰,因为新形式是 .terminal,而不是 .term ......无论如何......所以现在剩下的就是执行实际的 AS 脚本。'open' 是一个基本的命令行命令,就像在 Finder 中打开或双击一样。如果由于某种原因您的文件在错误的应用程序中打开或未打开,您可能需要将其映射到 Terminal.app(在获取信息窗口中)和/或将扩展名更改为更新'。终端'。killall 就像 kill 一样,旨在以各种方式杀死进程。我选择 -INT 是因为这本质上就像使用 control-c 来中断进程。]

于 2013-10-16T20:18:23.287 回答