• 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
NSAppleScript returns wrong result on multiple Safari windows, applescript editor work
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Resetting the TableView
  • Next by Date: Re: Recording video from a QCView to .mov
  • Previous by thread: NSAppleScript returns wrong result on multiple Safari windows, applescript editor work
  • Next by thread: Re: Strange behavior of observeValueForKeyPath:ofObject:change:context:
  • Index(es):
    • Date
    • Thread