Script editor works, Applescript does not ?

Hi


I have a one line script that works fine in the Apple Script Editor as:

tell application "Firefox" to return name of window 1 as string

The result instantly returns the page title. But this does not work using AppleScript / OSAScript.


Objective-C:

OSAScript *scriptNAME= [[OSAScript alloc] initWithSource:@"tell application \"Firefox\" to return name of window 1"];

returnDescriptor = [scriptNAME executeAndReturnError: &errorDict];


The result is nil, it also takes 2 seconds to work that out.



Any ideas what is wrong? I am using FireFox 55.0 64 bit.


Thanks
Geoff

Accepted Reply

I created a new test project and put your code into it (slightly tweaked, my version is pasted in below) and it works as expected, logging this:

2017-08-10 09:51:16.068210+0100 xxom[3464:234634] <NSAppleEventDescriptor: 'utxt'("Firefox Browser Privacy Notice — Mozilla")>

Have you tried this in a new test project? If not, I recommend that you do.

Also, is your main app sandboxed?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
OSAScript *scriptNAME= [[OSAScript alloc] initWithSource:@"tell application \"Firefox\" to return name of window 1"];
NSDictionary * errorDict = nil;
NSAppleEventDescriptor * returnDescriptor = [scriptNAME executeAndReturnError: &errorDict];
NSLog(@"%@", returnDescriptor);

Replies

I created a new test project and put your code into it (slightly tweaked, my version is pasted in below) and it works as expected, logging this:

2017-08-10 09:51:16.068210+0100 xxom[3464:234634] <NSAppleEventDescriptor: 'utxt'("Firefox Browser Privacy Notice — Mozilla")>

Have you tried this in a new test project? If not, I recommend that you do.

Also, is your main app sandboxed?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
OSAScript *scriptNAME= [[OSAScript alloc] initWithSource:@"tell application \"Firefox\" to return name of window 1"];
NSDictionary * errorDict = nil;
NSAppleEventDescriptor * returnDescriptor = [scriptNAME executeAndReturnError: &errorDict];
NSLog(@"%@", returnDescriptor);

Hi Eskimo


Thanks for the reply.


Ok, after testing in and out of Sand Box app, you are spot on, the app is Sandboxed as it is a store app, this stops direct FireFox AppleScript. Chome and Safari Applescript work fine in my sandboxed app. Is there a way around this as adding FireFox support to my app would be great.


Edit: will try adding priviliages but not got much hope looking at https://wiki.mozilla.org/Security/Sandbox




Cheers

Geoff

EDITED:


Ok, all working now, all I needed was the entitlement which I had forgot to include.


I added the entitlement: com.apple.security.temporary-exception.apple-events for org.mozilla.firefox

Many thanks for pointing me in the right direction.