NSAppleScript returns wrong result on multiple Safari windows, applescript editor work
NSAppleScript returns wrong result on multiple Safari windows, applescript editor work
- Subject: NSAppleScript returns wrong result on multiple Safari windows, applescript editor work
- From: Jot Kali <email@hidden>
- Date: Fri, 09 Jan 2009 00:08:21 -0800
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 (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