This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ronaldoussoren
Recipients AegisEmerald545, Auerhahn, TotallyLost, ned.deily, nicholasjbond2020, ronaldoussoren
Date 2021-12-12.13:19:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1639315195.72.0.652125210938.issue40477@roundup.psfhosted.org>
In-reply-to
Content
It looks like this is related to code signing and entitlements, in particular:

* On my system Terminal.app is in the "Automation" list in the Security & Privacy control panel, and none of the installed Python Launchers are
* The script let below works (assuming PyObjC is installed):
```
import ScriptingBridge

command = """cd '' && '/Library/Frameworks/Python.framework/Versions/3.10/bin/python3'  '/Users/ronald/issuequery.py'  && echo Exit status: $? && exit 1"""

app = ScriptingBridge.SBApplication.applicationWithBundleIdentifier_("com.apple.Terminal")

app.activate()
res = app.doScript_in_(command, None)
print(res)
```

* Python Launcher does not work when launched normally
* Python Launcher *does* work when I run "/Applcations/Python 3.X/Python Launcher/Contents/MacOS/Python Launcher" in Terminal.app and try to open a python file using Python Launcher
  - I've tried this with 3 variants of Python Launcher: 3.9.7 from python.org installer, no modifications; 3.10.1 from python.org installer, stripped signature and resigned ad-hoc; 3.11 installed from source with ScriptingBridge.

As mentioned before I've experimented with ScriptingBridge in Python Launcher, replacing "doscript.m" by the code below:
```
#import <Cocoa/Cocoa.h>
#import <ScriptingBridge/ScriptingBridge.h>
#import "doscript.h"

extern int
doscript(const char *command)
{
    NSObject* terminalApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.Terminal"];
    //[terminalApp activate];
    NSObject* res = [terminalApp doScript:[NSString stringWithUTF8String:command] in:nil];

    NSRunAlertPanel(@"script result", @"%@", @"ok",nil, nil, res);

    return 0;
}
```

That's equivalent to the python code I posted earlier. This is not production quality code, it compiles with a warning about "doScript:in:" that can be avoided by a different way of using ScriptingBridge. That's irrelevant for this experiment though.

When I test the call to "doScript:in:" *fails* (returns nil) when launching the app regularly, and *succeeds* when running as a terminal command (as mentioned earlier).
History
Date User Action Args
2021-12-12 13:19:55ronaldoussorensetrecipients: + ronaldoussoren, ned.deily, Auerhahn, TotallyLost, nicholasjbond2020, AegisEmerald545
2021-12-12 13:19:55ronaldoussorensetmessageid: <1639315195.72.0.652125210938.issue40477@roundup.psfhosted.org>
2021-12-12 13:19:55ronaldoussorenlinkissue40477 messages
2021-12-12 13:19:55ronaldoussorencreate