What replaces 'Internet Connect' for dial-up connection in Leopard?

G’day scripters

I’ve had a request to change my ‘Dial-up Mail Checker’ script to work with Leopard.

Trouble is, Leopard no longer uses the ‘Internet Connect’ to establish a dial-up connection. I’m on broadband now so don’t know what to alter in my old script.

Can anyone make the necessary alterations, or make some suggestions please?

Regards

Santa



-- Dial-up Mail Checker
-- Version 1.4

-- Not Bloody Copyright
-- By Santa 2006
-- Sunny Land of Oz
-- bec9@tpg.com.au

-- I owe much of the scripting to folks at MacScripters.
--    http://macscripter.net/

-- NOTE : Must be saved as a 'Stay Open' application
-- BUT, you can use any name, it will still work.

-- Rename & save one as a 'run once' App.
-- and one as 'run every X minutes' App.

-- This Application is designed to work with timed or untimed phone calls,
-- but also picks up if you have other active connections, such as broadband.

-- Edit the Application script to set parameters.

-- ======================================
-- Set Mail.app Preferences/General to 'Check for mail manually'. =
-- Set PPP Options to 'Connect Automatically when needed'         =
-- if you want to.                                                                        =
-- ======================================

-- NOTE that if  you have the sounds turned off in Mail.app, and
-- have 'DisplayMailMessage' set to 'false' then you'll get no feedback
-- when there's new mail; in fact, this App will seem to be not working.

-- ========= Stuff you can change ================
global interval
-- Set this for time between checking mail. 
-- (it's in minutes)
set interval to 10 -- minutes

global DisplayMailMessage
-- Set this to 'false' if you don't want to see 
-- the 'New Mail' message, otherwise 'true'.
set DisplayMailMessage to true

global RunJustOnce
-- Set this to 'true' if you want to only check 
-- for 'New Mail' once, then Quit, otherwise 'false'.
-- Note that existing connections stay open.
set RunJustOnce to false

global IveGotUntimedCalls
-- This is for the Aussies.
-- This is as read. If you're lucky enough to have untimed
-- phone calls, then set this to 'true'; then it won't hang up
-- after  checking your eMail. If you want it to hang up, 
-- (if not allready online), then leave as 'false'.
set IveGotUntimedCalls to false

-- ======================================

-- Don't fiddle!
global the_count
global NewMailFlag
global AllReadyOnline
set AllReadyOnline to "FirstRun"
property repeat_time : 60

my mainloop()

on idle
	if RunJustOnce then
		if NewMailFlag then
			my ShowMailWindow()
		end if
		my QuitQuick()
	end if
	
	if the_count = interval or the_count > interval then
		my mainloop()
	end if
	set the_count to the_count + 1
	return repeat_time
end idle

on mainloop()
	set the_count to 0
	if AllReadyOnline is not "IP_AllreadyConnected" then -- Found another connection before, so bypass
		tell application "Finder"
			try
				tell application "System Events"
					tell window 1 of process "Internet Connect"
						if exists button "Cancel" then
							tell application "Network Utility"
								quit
								delay 5
							end tell
						end if
					end tell
				end tell
			end try
			
			try
				if not (exists process "Internet Connect") then
					activate application "Network Utility"
					my SendWindowToDock()
				end if
			end try
			
		end tell
		-- This will be picked up at each pass, so if user has disconnected, will execute as per settings
		if my CheckOnLine() is equal to 8 then
			my SendWindowToDock()
			set AllReadyOnline to "AllreadyConnected"
		else
			if my CheckOnLine() is equal to 1 then
				display dialog "Internet Connect appears to be hung." buttons "So, I'll Quit"
				my QuitQuick()
			end if
			if my CheckIPAddress() is not equal to "OffLine" then -- We've found an IP address!
				set AllReadyOnline to "IP_AllreadyConnected"
				my DisconnectInternetConnect()
				my QuitInternetConnect()
				if RunJustOnce then
					set TagOn to " just the once?"
				else
					set TagOn to " every " & interval & " minutes?"
				end if
				display dialog "It appears that you have an Internet connection other than a dial-up one." & return & return & "You have an IP  address of " & my CheckIPAddress() & return & return & "Do you want to use this application to check your mail" & TagOn buttons {"Quit this application", "Yes please"}
				if the button returned of the result = "Yes please" then
					my GetMail()
					return
				else
					my QuitQuick()
				end if
			end if
			tell application "Network Utility"
				activate
			end tell
			my SendWindowToDock()
			tell application "System Events"
				tell application "Network Utility"
					«event netcconn»
					set x to 0
					try
						repeat until «class RAsb» of «class RSst» of «class ccnf» is equal to 8
							delay 0.2
							set x to x + 1
							if x = 300 then
								display dialog "There seems to be a problem." & return & return & "I've waited for a minute, but there's no dial up connection to the server." & return buttons "So, I'll Quit"
								my QuitQuick()
							end if
						end repeat
						set AllReadyOnline to "HadToConnect"
					end try
				end tell
			end tell
		end if
	end if
	
	my GetMail()
	
	if IveGotUntimedCalls is false and AllReadyOnline is "HadToConnect" then
		my DisconnectInternetConnect()
		if RunJustOnce then my QuitInternetConnect()
	end if
	
end mainloop

-- ======= Sub-Routines =============

on GetMail()
	tell application "Finder"
		if not (exists process "Mail") then
			tell application "Mail"
				activate
				set visible of windows to false
			end tell
		end if
	end tell
	tell application "Mail"
		set ExistingUnread to unread count of inbox
		set ExistingOutbox to count of messages in outbox
		check for new mail
		delay 0.2
		repeat until background activity count = 0
			delay 0.1
		end repeat
		set NewUnread to (unread count of inbox) - ExistingUnread
		set NewMailFlag to NewUnread > 0
		set NewOutbox to count of messages in outbox
		set SentOutbox to ExistingOutbox - NewOutbox
	end tell
	if ExistingUnread = 0 then
		set OldDisplayString to "no old unread ones."
	else
		if ExistingUnread = 1 then
			set OldDisplayString to "one older unread one."
		else
			set OldDisplayString to ExistingUnread & " older unread ones."
		end if
	end if
	set SentString to ""
	if SentOutbox = 1 then set SentString to return & return & "One eMail was sent"
	if SentOutbox > 1 then set SentString to return & return & SentOutbox & " eMails were sent."
	if NewUnread > 0 then
		if NewUnread = 1 then
			set NewDisplayString to "eMail, and "
		else
			set NewDisplayString to "eMails, and "
		end if
		if DisplayMailMessage then
			tell application GetMyName()
				activate
				display dialog "You have " & NewUnread & " new " & NewDisplayString & OldDisplayString & SentString buttons {"Stop this window", "Continue checking", "I'll read mail please"} with icon note giving up after interval * 60
			end tell
			set ButtonReturned to the button returned of the result
			if ButtonReturned is "I'll read mail please" then
				ShowMailWindow()
			else
				if ButtonReturned is "Stop this window" then set DisplayMailMessage to false
			end if
		end if
	end if
end GetMail

on ShowMailWindow()
	activate application "Mail"
	tell application "Mail"
		try
			set IsVisible to visible of window 1
			if IsVisible is false then
				my ShowWindow()
			end if
		on error
			my ShowWindow()
		end try
	end tell
end ShowMailWindow

on ShowWindow()
	tell application "System Events" to tell application process "Mail" to tell menu bar 1 to tell menu bar item 3 to tell menu 1 to tell menu item 2
		click
	end tell
end ShowWindow

on SendWindowToDock()
	tell application "System Events"
		try
			if exists application "Network Utility" then
				repeat with btn in (buttons of (get window 1 of application process "Internet Connect" of application "System Events"))
					if value of attribute "AXSubrole" of btn is "AXMinimizeButton" then
						perform action "AXPress" of btn
						exit repeat
					end if
				end repeat
			end if
		end try
	end tell
end SendWindowToDock

on CheckOnLine()
	tell application "Network Utility"
		-- Are we already online? Should be 8 if yes.
		try
			set temp to «class RAsb» of «class RSst» of «class ccnf»
		on error
			set temp to 1
		end try
	end tell
	return temp
end CheckOnLine

on CheckIPAddress()
	do shell script "curl http://checkip.dyndns.org/ | grep 'Current IP Address' | cut -d : -f 2 | cut -d \\< -f 1"
	if result = "" then
		return "Offline"
	else
		return (characters 2 through -1 of result) as text
	end if
end CheckIPAddress

on DisconnectInternetConnect() -- We're gonna disconnect!
	tell application "Finder"
		if not (exists process "Internet Connect") then
			tell application "Network Utility"
				activate
				my SendWindowToDock()
			end tell
		end if
		tell application "Network Utility"
			«event netcdcon»
		end tell
	end tell
end DisconnectInternetConnect

on QuitInternetConnect()
	tell application "Finder"
		tell application "Network Utility"
			quit
		end tell
	end tell
end QuitInternetConnect

-- Use this so the App can be any name.
on QuitQuick()
	tell application "System Events"
		try -- Should stop the application with no dialogs and no items saved.
			do shell script "kill -9 " & (unix id of processes whose name is my GetMyName())
		end try
	end tell
end QuitQuick

on GetMyName()
	set temp to (name of (info for (path to me)))
	set temp2 to replace_chars(temp, ".app", "")
	return temp2
end GetMyName

on replace_chars(this_text, search_string, replacement_string)
	set StoreDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list as string
	set AppleScript's text item delimiters to StoreDelimiters
	return this_text
end replace_chars


Hi Santa,

in Leopard Network Preferences are scriptable in System Events. See release notes
There is also a new CLI networksetup added in Leopard