Launch programs on start up if computer is connected to internet

Hi MacScripter Forum

There is nothing revolutionary about this script I’m posting but I referred to this site heavy in order to write it. Hence it’s good form to post what I’ve created in case anyone else finds it interesting. I’m also interest in possible improvements for the script as I’m a scripting noob that is still learning what makes good and bad scripting practice.

SCRIPT README

THE NET_LOGIN_ITEMS CODE


-- initialize variables
set flaunch to "false"
set tlaunch to "false"
set rlaunch to "false"
set nonet to "false"
try
	set thePing to do shell script "ping -o -c 1 (* insert IP address of choice *)" -- ping a server to check for connectivity
on error
	set nonet to "true" -- If the ping fails set nonet to true
end try
if nonet ≠ "true" then -- if nonet is true, the ping has failed, your computer isn't connected to the internet, the rest of the script is skipped
	delay 30 -- delay the script so other start up processes can end before this script starts loading new items
	tell application "Firefox" to activate -- Launch Firefox
	tell application "Thunderbird" to activate -- Launch Thunderbird
	tell application "iChat" -- Launch iChat
		set status to available -- set iChat status to available
		quit -- quit iChat (uncheck the iChat setting 'When I quit iChat, set my status to Offline')
	end tell
	repeat while rlaunch = "false" -- Clean up tasks
		if flaunch is "false" then -- Firefox clean up
			tell application "System Events"
				tell application process "firefox-bin"
					set frontmost to true -- bring Firefox to the front
					if ((count each window) > 0) then -- check if a Firefox window is displayed
						do shell script "open -a firefox [url=http://mail.yahoo.com/]http://mail.yahoo.com/"[/url] -- load a web page that isn't the homepage
						keystroke "h" using command down -- hide Firefox (Crtl-H)
						set flaunch to "true" -- Now that Firefox has gone through the clean up process set flaunch to true
					end if
				end tell
			end tell
		end if
		if tlaunch is "false" then -- Thunderbird clean up
			tell application "System Events"
				tell application process "thunderbird-bin"
					set frontmost to true -- bring Thunderbird to the front
					if ((count each window) > 0) then -- check if a Thunderbird window is displayed
						keystroke "h" using command down -- hide Thunderbird (Crtl-H)
						set tlaunch to "true" -- Now that Thunderbird has gone through the clean up process set tlaunch to true
					end if
				end tell
			end tell
		end if
		if flaunch is equal to "true" then -- Check if Firefox is cleaned up
			if tlaunch is equal to "true" then -- Check if Thunderbird is cleaned up
				set rlaunch to "true" -- If conditions are met set rlaunch to true to end clean up loop else repeat
			end if
		end if
	end repeat
end if

This script is specifically designed for my needs but the principles can be used in many applications.

Reactor89

Model: 2007 MacBook Pro
AppleScript: 10.6.5
Browser: Firefox 3.6.8
Operating System: Mac OS X (10.6)

Good idea! :cool: FYI: I just posted something very similar here so maybe you’d be interested:
http://macscripter.net/viewtopic.php?pid=131362