• 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: Grabbing current Safari webpage url
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Grabbing current Safari webpage url


  • Subject: Re: Grabbing current Safari webpage url
  • From: has <email@hidden>
  • Date: Fri, 7 Mar 2008 09:50:55 +0000

Steve Sheets wrote:

Is there a way of finding out what is the current topmost webpage
being viewed by Safari? Somehow then grabbing the url & title of that
page?

Using objc-appscript (http://appscript.sourceforge.net/objc-appscript.html ):


#import <Foundation/Foundation.h>
#import "SFGlue/SFGlue.h"

// To make Safari glue:  osaglue  -o SFGlue  -p SF  Safari

int main (int argc, const char * argv[]) {
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

SFApplication *safari = [[SFApplication alloc] initWithBundleID: @"com.apple.safari"];

if ([safari isRunning]) {

SFReference *docRef = [[safari documents] at: 1];

NSError *err;


		// get front document's name
		id name = [[[docRef name] get] sendWithError: &err];

		if (name)
			NSLog(@"Title: %@", name);
		else
			NSLog(@"Error:\n%@", err);

		// get its URL
		id url = [[[docRef URL] get] sendWithError: &err];

		if (url)
			NSLog(@"URL: %@", url);
		else
			NSLog(@"Error:\n%@", err);

	} else
		NSLog(@"Safari is not running.");

	[safari release];
	[pool drain];
	return 0;
}

HTH

has
--
http://appscript.sourceforge.net

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: GetMonitorFromWindow
  • Next by Date: Re: How to debug a nib loading error?
  • Previous by thread: Re: Grabbing current Safari webpage url
  • Next by thread: Re: Grabbing current Safari webpage url
  • Index(es):
    • Date
    • Thread