Hello,

Still working on this problem. I need to get Safari most current URL. NSAppleScript does not work since it returns the wrong result, or it needs to activate Safari which isn't a solution.

I'm now trying osascript called via an NSTask. This works in Terminal :

/usr/bin/osascript -e 'tell application "Safari" to get URL of current tab of window 1'

However calling this within my program results in :

33:36: execution error: Safari got an error: Can’t get current tab of window 1. (-1728)

Why ?

Calling with this :
__
NSTask *task = [[[NSTask alloc] init] autorelease];
[task setLaunchPath: @"/usr/bin/osascript"];
                
NSString *command = @"tell application \"Safari\" to get URL of current tab of window 1";
NSArray *arguments = [NSArray arrayWithObjects: @"-e", command, nil];
[task setArguments: arguments];
                
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file = [pipe fileHandleForReading];

[task launch];

NSData *data = [file readDataToEndOfFile];
NSString *string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"got\n%@", string);
__

thanks._______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to