Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 应用程序总是给出-1708_Bash_Applescript_Runtime Error - Fatal编程技术网

Bash 应用程序总是给出-1708

Bash 应用程序总是给出-1708,bash,applescript,runtime-error,Bash,Applescript,Runtime Error,我正在做一个基本的ping测试,以扩展我对bash和Applescript的知识,因此我做了以下测试: on run argv try if (count argv) is less than 1 or (count argv) is greater than 1 then set IP_address to "" set dialog_1 to display dialog "Enter IP Address:" default answer "" wi

我正在做一个基本的ping测试,以扩展我对bash和Applescript的知识,因此我做了以下测试:

on run argv
try
    if (count argv) is less than 1 or (count argv) is greater than 1 then
        set IP_address to ""
        set dialog_1 to display dialog "Enter IP Address:" default answer "" with title "Ping"
        set the IP_address to the text returned of dialog_1
        try
            set ping to (do shell script "ping -c 2 " & IP_address)
            display dialog "Connection Successful." buttons {"OK"} default button 1
            return 1
        on error
            --if we get here, the ping failed
            display dialog "Conection failed. Host is down" buttons {"Darn"} default button 1
            return 0
        end try
    end if
    if (count argv) = 1 then
        set IP_address to item 1 of argv
        try
            set ping to (do shell script "ping -c 2 " & IP_address)
            return 1
        on error
            -- if we get here, the ping failed
            return 0
        end try
    end if
on error error_message number error_number
    if (error_number) is not equal to -128 then
        display alert ("An error has occured!") message error_message & (" Error number ") & error_number & "."
    end if

    return error_number
end try
终点

(我无法在代码段中获得结束运行)

在bash中,我做了这样一件事:

on run argv
try
    if (count argv) is less than 1 or (count argv) is greater than 1 then
        set IP_address to ""
        set dialog_1 to display dialog "Enter IP Address:" default answer "" with title "Ping"
        set the IP_address to the text returned of dialog_1
        try
            set ping to (do shell script "ping -c 2 " & IP_address)
            display dialog "Connection Successful." buttons {"OK"} default button 1
            return 1
        on error
            --if we get here, the ping failed
            display dialog "Conection failed. Host is down" buttons {"Darn"} default button 1
            return 0
        end try
    end if
    if (count argv) = 1 then
        set IP_address to item 1 of argv
        try
            set ping to (do shell script "ping -c 2 " & IP_address)
            return 1
        on error
            -- if we get here, the ping failed
            return 0
        end try
    end if
on error error_message number error_number
    if (error_number) is not equal to -128 then
        display alert ("An error has occured!") message error_message & (" Error number ") & error_number & "."
    end if

    return error_number
end try
!/bin/bash currentDir=
pwd
Success=
$currentDir/$1/Contents/MacOS/applet$2
回声$成功

(我无法在代码片段中获得这些信息)

当我只运行AppleScript时,在编辑器中它工作正常,但是.app和bash版本给了我-1708错误。我已将问题缩小到以下范围:
如果(count argv)小于1或(count argv)大于1,则

我能做些什么来修复这个问题,或者干脆让我的代码更整洁

谢谢


编辑(1):如果没有提供任何参数,我希望我的程序运行GUI版本,并且当传递参数时,我希望它在后台运行。

您可以直接从bash向AppleScript传递参数,如下所示:

--AppleScript named myScript.scpt
    on run {argv}
        beep argv
    end run 
命令:

osascript -e 'run script "/Users/user1781742/Desktop/myScipt.scpt" with parameters {2}'

谢谢,但是如果没有提供任何参数,我希望我的程序运行GUI版本,当传递参数时,我希望它在后台运行。(将添加到OP)