The 'classic' method of scripting a connection attempt goes something like this:
tell application "Black Night" open helper "Atlantis" wait until connection of document "Atlantis" becomes active timeout 50 if not result then return "Unable to Connect" return "" end tell
If the connection attempt failed, then the "Wait" command would timeout after 50 seconds and get captured as a generic failure.
This script will still work, but now you can also do this:
tell application "Black Night" open helper "Atlantis" wait until connection of document "Atlantis" becomes idle timeout 50 if not result then return "Out to Lunch" set localResult to errcode of connection of document "Atlantis" --- -128 is user canceled if localResult is equal to -128 then return "You canceled !" --- 0 is usually success, you may want to check the status though if localResult is equal to 0 then return "" --- some other error - report it return localResult end tell
The change is the addition of the "errcode" property which returns the error code returned by the connection tool after the last connection attempt. Note that connection tools are rather sporadic in the manner in which they return error codes and hence this is not 100% reliable. If you're really paranoid then you should check the status of the connection to make sure it really is open.
The other change is the "status" property now includes an enumeration "idle", which means that it's either connected or not connected. This enumeration is only referenced by the wait command (i.e. if you read the status directly - you will not get "idle" returned).
Version 1.0.7 of Black Night introduces "Auto Print" mode in addition to "Print Controller" mode. In an odd sort of way, this allows you to implement text capture using a couple of very simple AppleScripts. If you leave the scripts in the "Home Base" folder, then the'll show up in the script menu.
Script to turn text capture on:
tell application "Black Night" set contents of document 1 to "^[[?5i" end tell
Script to turn text capture off:
tell application "Black Night" set contents of document 1 to "^[[?4" end tell
The command to set the contents of the document just sends the string to the terminal and not to the connection. This was originally intended to allow you to send your own "splash" message to be displayed on the terminal but it also allows you to send terminal control strings. The funny strings sent are the control strings to turn printing (or in this case text capture) on and off.
The following script uses the Black Night Modem Tool to call a repeatedly call a number until a connection attempt succeeds, or the maximum number of failures is exceeded. This script (in a modified form) can be used by ISPs and System Administrators to keep a check on your modem banks.
tell application "Black Night"
set localFailures to 0
set localResult to 1
set connection of document 1 to "Black Night Modem Tool"
set configuration of connection of document 1 to "PhoneNumber \"3841282\" attempts 1"
repeat while (localResult is not equal to 0) and (localFailures is less than 99)
open connection of document 1
wait until connection of document 1 becomes idle
set localResult to errcode of connection of document 1
if localResult is not equal to 0 then set localFailures to (localFailures + 1)
end repeat
close connection of document 1
end tell
display dialog "Total Failures = " & localFailures buttons {"OK"} default button "OK"
return ""