我正在做一个基本的pingtest来扩展我对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
结束运行
(我无法在代码代码段中进行结束运行)
,在狂欢中,我做到了:
!/bin/bashCurrentDir = pwd
成功= $currentDir/$1/Contents/MacOS/applet $2
Echo $成功
(我无法在代码段中获得任何内容)
当我仅运行AppleScript时,在编辑器中运行良好,但是.App和bash版本给我-1708错误。我把问题缩小到了: if (count argv) is less than 1 or (count argv) is greater than 1 then
我该怎么做才能解决这个问题,甚至只是使我的代码不整洁?
谢谢
编辑(1):如果没有提供任何参数,我希望我的程序运行GUI版本,并且当它通过参数时,我希望它在后台运行。
您可以将参数直接传递给applescript,直接从bash这样的bash:
--AppleScript named myScript.scpt
on run {argv}
beep argv
end run
命令:
osascript -e 'run script "/Users/user1781742/Desktop/myScipt.scpt" with parameters {2}'