Shell script error type 1


Within a script I’ve written I am calling the following procedure to determine if something is operating on a tcp port 8342.

on port_loaded(timeout_value)
repeat with i from 1 to the timeout_value
tell application “System Events”
do shell script “netstat -a | grep 8342”
if the result is not “” then
return true
else if i is the timeout_value then
return false
delay 1
end if
end tell
end repeat
return false
end port_loaded

When it runs it stops with a “System Events has returned a Type 1 error”
and highlights the shell script line.

Anyone know what the error means and why its happening?



First, System Events isn’t really doing anything and doesn’t need to be part of the script because the “do shell script” command operates independently of any application. Second, I get the same error when grep is searching for something that returns no result so simply adding a try block should resolve the issue for you. Also, the script can be optimized a bit:


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

G’day Jon,

The “try” “end try” worked a treat !!!

Thanks for your help.

Much appreciated…

Dennett :smiley: