• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Communicating With Browser
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Communicating With Browser


  • Subject: Re: Communicating With Browser
  • From: Zack Morris <email@hidden>
  • Date: Wed, 10 Nov 2004 06:32:56 -0700

On Nov 9, 2004, at 8:09 PM, Zack Morris wrote:

Well, it appears that you can't get the source of an apple event in carbon, or OS X. That's kind of a deal breaker for me, I dunno, I just don't think that applescript is very useable in the real world. It's pretty (like HyperTalk), but under the hood it is just really hard to use. I tend to do a lot of trolling though :) I tried this code:

OK I downloaded the SimpleRunAppleScript() routine from http://developer.apple.com/qa/qa2001/qa1026.html (thanx Quinn!) I wrote the following applescript which opens a page in the browser without causing a reload if it's already open. It brings the page to the front if the user already has it open behind other windows. There is a slight hiccup for a second as it compiles the script, so when using applescripts often, it would be better to go with compiled scripts with the routines on http://developer.apple.com/qa/qa2001/qa1111.html. On the bright side, the scripts seem to get cached, or the compiler stays loaded, because I never see another hiccup. Since I am just switching to the browser though, I don't care about speed. I use internet config to get the name of the default browser and set kBrowser from inside C++ with string concatenation. Curiously, none of the mozilla browsers seem to work with applescripts yet, aside from the most basic open url command. I was unable to run javascripts or manipulate windows in FireFox or Opera either, at least not well enough to add their cases to this script. Haven't tried iCab or any others yet.


------------------------------------------------------------------------
Zack Morris              Z Sculpt Entertainment               This Space
email@hidden      http://www.zsculpt.com                 For Rent
------------------------------------------------------------------------
If the doors of perception were cleansed, everything would appear to man
  as it is, infinite. -William Blake, The Marriage of Heaven and Hell

--------------------------------------------------------------

--Script to open the url, but only if it's not already open

copy "http://www.apple.com"; to kPageURL --page to open
copy "Safari" to kBrowser -- put the browser you wish to open here

--Change nothing below this line, unless you add more browsers

on Safari()
	global kPageURL

	tell application "Safari"
		activate

		set found to false
		repeat with i from 1 to count of windows
			URL of document of window i as string
			if result is kPageURL then
				set found to true
				exit repeat
			end if
		end repeat

		if found then
			set index of window i to 1
		else
			open location kPageURL
			--set the URL of (make new document) to kPageURL
		end if

		--delay 1
		--do JavaScript "document.title" in document 1
		--display dialog result
	end tell
end Safari

on InternetExplorer()
	global kPageURL

	tell application "Internet Explorer"
		Activate

		set found to false
		repeat with i in ListWindows
			copy (GetWindowInfo i) to theList
			copy item 1 of theList to theURL
			--copy item 2 of theList to theName

			if theURL is kPageURL then
				set found to true
				exit repeat
			end if
		end repeat

		if found then
			Activate i
		else
			OpenURL kPageURL toWindow 0
		end if

		--delay 1
		--do script "document.title" window 1
		--display dialog result
	end tell
end InternetExplorer


on OmniWeb() global kPageURL tell application "OmniWeb" activate set found to false set counter to 1 repeat with i in ListWindows copy (GetWindowInfo i) to theList copy item 1 of theList to theURL --copy item 2 of theList to theName if theURL is kPageURL then set found to true exit repeat end if copy counter + 1 to counter end repeat if found then set index of window counter to 1 else OpenURL kPageURL toWindow 0 end if --delay 1 --do script "alert( document.location )" window -1 --display dialog result --result is undefined!!! end tell end OmniWeb

if kBrowser is "Safari" then
	Safari()
else if kBrowser is "Internet Explorer" then
	InternetExplorer()
else if kBrowser is "OmniWeb" then
	OmniWeb()
else
	open location kPageURL
end if

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Communicating With Browser
      • From: Quinn <email@hidden>
References: 
 >Re: testing for firewall and modifying ports (From: Ryan McGann <email@hidden>)
 >Communicating With Browser (From: Zack Morris <email@hidden>)
 >Re: Communicating With Browser (From: Quinn <email@hidden>)
 >Re: Communicating With Browser (From: Zack Morris <email@hidden>)
 >Re: Communicating With Browser (From: Zack Morris <email@hidden>)

  • Prev by Date: Re: Communicating With Browser
  • Next by Date: Converting float array to UInt8 for writing to a stream.
  • Previous by thread: Re: Communicating With Browser
  • Next by thread: Re: Communicating With Browser
  • Index(es):
    • Date
    • Thread