University of Oregon

Testing web pages in multiple browers with appleScript v.2

This is a follow up to a post from a few years ago: Using applescript to open a url in several browsers.
I’ve made some updates to the script since then and a few them were today so I thought I’d share.

The old script opened a URL in several browsers (failing to load the web page in parallels VM browsers). The updated script now plays nice with Parallels and captures any URL in your clipboard if applicable.
The key to playing nice with Parallels is to manually drag the application icon into the script so that the address of the browser in the remote VM is accessible to the script.
Here’s the updated script: (more…)

Reestablish an external network connection in a Parallels VM

I couldn’t get an external network connection in my recently imported Red Hat Enterprise Linux 6 image.

This was really difficult to troubleshoot. The “Network settings” preference GUI was missing (perhaps because of the network failure on startup. and the CMD Line version (system-config-network) wasn’t very helpful either.

So this morning I open another copy of the VM to start with a clean slate.

This time I notice an error message icon at the bottom of the login screen. I looked through the log and saw a couple of failures. The first one caught my eye: “Bringing up interface eth0; Device eth0 does not seem to be present, delaying initialization.” [failure]

I searched Google for that sentence and found this post that outlined the exact fix I needed: http://kezhong.wordpress.com/2011/02/04/solving-the-problem-unable-to-activate-nics-after-moved-the-hard-driver-from-a-machine-to-another/
So I confirmed that the OS changed eth0 to eth3 on startup and wasn’t able to get a dhcp. Here are the steps I used (Note: # are comments).

Cmds:

#Verify Error:
$ sudo service network restart
#note any ‘eth’ related errors
$ dmesg | grep eth
## Note: use the results of this command to determine the old and new eth names.
## Result: “udev: renamed network interface eth0 to eth3″
## So in this case I will move ifcfg-eth0 to ifcfg-eth3
$ cd /etc/sysconfig/network-scripts;
$ sudo mv ifcfg-eth0 ifcfg-eth3
$ sudo vim ifcfg-eth3
## Change: DEVICE=”eth0″ to DEVICE=”eth3”
## Save: :wq
$ sudo service network restart
## Result: “Bringing up interface eth3: Device eth3 has different MAC address than expected, ignoring.”
## Get the MAC addresses, and append it to ifcfg-eth3 files.
$ sudo cat /sys/class/net/eth3/address >> ifcfg-eth3
## If you get permission denied you can either su as root or just hand type the mac address; which can be found in the Parallels VM config GUI
$ su root
## Failed. Password isn’t known…
$ sudo passwd root
## set the root password… (Who knew you could sudo set the root password. Pretty handy!)
$ su root
$ cat /sys/class/net/eth3/address >> ifcfg-eth3
$ exit
$ sudo vim ifcfg-eth3
## Change: HWADDR=”… to match the appended mac address and delete appended text.
## Save: :wq
$ sudo service network restart

Success!
Now I have internet connectivity for the VM!

*This worked for the 2nd copy of the vm I imported as well but in that case eth0 was changed to eth1.

using applescript to open a url in several browsers

I want to test pages in multiple browsers (7 at this point) but I don’t want to cut and paste so I put together a quick and dirty applescript to help.
I does have a small drawback of not being able to open urls in browsers that live in a Parallels virtual machine but it does open the browsers so that’s a start.

I toyed with the idea of setting the preferences in Parallels dynamically; switching the default handing of web pages to windows and, calling the applescript ‘open location’ command (that uses the default web browser) and then switch back again but that may be too much effort. This get’s the job done.

--openUrls.applescript
--A finder AppleScript
--
--Opens a url in multiple browsers
--
property listOfBrowsers : {"Firefox", "Safari", "/Applications/Chrome.app", "Opera", "/Users/Shared/Parallels/Windows 7.pvm/Windows Applications/Internet Explorer.app", "/Users/Shared/Parallels/Windows 7.pvm/Windows Applications/Firefox.app"}

try
	set goToUrl to (get the clipboard)
	try
		set goToUrl to goToUrl as string
		set firstFourUrl to (characters 1 thru 4 of goToUrl) as string
	on error
		set goToUrl to ""
	end try

	if firstFourUrl is not "http" then
		set goToUrl to ""
	end if

	try
		if goToUrl is "" then
			tell me to activate
			set goToUrl to the text returned of (display dialog "The clipboard was empty or not a well formed URL. Please copy your URL and try again." default answer "http://hr.uoregon.edu") -- giving up after 4

			if goToUrl is "" then
				display dialog "The clipboard could not be converted into text. Please copy your URL and try again."
				return false
			end if
		end if
	end try
end try

if goToUrl is not "" then
	try
		repeat with oneBrowser in listOfBrowsers
			tell application oneBrowser
				activate
				open location goToUrl
			end tell
			delay 1
		end repeat
	on error errMsg number errNum
		error errMsg number errNum
	end try
end if