Ronald Oussoren <[email protected]> added the comment:
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).
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40477>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com