Re: Grabbing current Safari webpage url
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