• 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 works
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSAppleScript returns wrong result on multiple Safari windows, applescript editor works


  • Subject: NSAppleScript returns wrong result on multiple Safari windows, applescript editor works
  • From: Jot Kali <email@hidden>
  • Date: Thu, 18 Dec 2008 13:54:30 -0800

Hello,

I'm trying to get the URL of whatever is the front window / selected tab in Safari. But for multiple windows it does not work.

Say the user opens a window in Safari and navigates to apple.com, opens a tab and goes to nytimes.com, opens a NEW window and goes to arstechnica.com

If I run this script in Script Editor it works every time, returns arstechnica.com (the URL of the new front window) :

tell application "Safari"
	return URL of front document as string
end tell


However if I do this in my Cocoa app :

	NSDictionary *dict;
    NSAppleEventDescriptor *result;

NSAppleScript *script = [[NSAppleScript alloc] initWithSource: @"\ntell application \"Safari\"\n\tget URL of front document \nend tell \n"];
result = [script executeAndReturnError:&dict];


    [script release];

if ((result != nil) && ([result descriptorType] != kAENullEvent)) {;
NSLog (@"URL %@", [result stringValue]);
}



It returns nytimes.com. It always returns the last tab of the FIRST window that was opened in safari. I have to close that window to get it to return the actual front most window site arstechnica.com.


I tried both 'front document' and 'document 1', both no go.

Any hints on what is going wrong?

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: proper way to release a static NSMutableDictionary?
  • Next by Date: Problem when userSpaceScaleFactor is not 1.0
  • Previous by thread: subclassing NSApplication run
  • Next by thread: NSAppleScript returns wrong result on multiple Safari windows, applescript editor works
  • Index(es):
    • Date
    • Thread