Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Grabbing current Safari webpage url



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.