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…)

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