An Electron app uses NSAppleScript in a child python process and it needs automation controls for each browser. I have isolated the issue down to this specifically because if I run the app in the terminal with control of safari it works and without control of safari it does not. All I am using these permissions for are to get URL's so if there is a simpler way to do that I am open to hearing it.
How can I ask the user for permission using electron, python, or AppleScript and are there specific things I need in files like info.plist, parent.entitlements, child.entitlements? Thank you so much in advance.
To note, electron-forge is the compiler being used.
All relevant code snippets are below
if browser_name == "Safari":
browser_tab_name = NSAppleScript.alloc().initWithSource_(
str(f"""
tell application "{browser_name}"
get URL of current tab of window 1
end tell
"""))
This is one of the ways I am using the AppleScript for one browser. I also use AppleScript to find the URL of chromium based browsers
Here is my package.json
{
"name": "PowerTimeTracking",
"productName": "PowerTimeTracking",
"version": "0.1.0",
"description": "An app to improve productivity by blocking apps that waste time and showing where time goes.",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"package-arm": "electron-forge package --arch=arm64",
"make": "electron-forge make",
"make-arm": "electron-forge make --arch=arm64",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\""
},
"keywords": [],
"author": {
"name": "Shorya Malani",
"email": "shoryamal@gmail.com"
},
"license": "MIT",
"config": {
"forge": {
"electronPackagerConfig":{
"icon": "./src/assets/icon.icns",
"extendInfo":{
"NSAppleScriptEnabled": true,
"NSAppleEventsUsageDescription":"Applescript is needed to get tab urls of websites."
}
},
"packagerConfig": {
"osxSign": {
"identity": "Developer ID Application: Shorya Malani (YD5J62KXTT)",
"hardened-runtime": true,
"entitlements": "parent.entitlements",
"entitlements-inherit": "parent.entitlements",
"signature-flags": "library"
}
},
"makers": [
{
"name": "@electron-forge/maker-squirrel",
"config": {
"name": "forgepowertimetracking"
}
},
{
"name": "@electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "@electron-forge/maker-deb",
"config": {}
},
{
"name": "@electron-forge/maker-rpm",
"config": {}
}
]
}
},
"dependencies": {
"@electron/osx-sign": "^1.0.1",
"electron-squirrel-startup": "^1.0.0",
"node-fetch": "^2.6.7",
"python-shell": "^3.0.1"
},
"devDependencies": {
"@electron-forge/cli": "^6.0.0-beta.63",
"@electron-forge/maker-deb": "^6.0.0-beta.63",
"@electron-forge/maker-rpm": "^6.0.0-beta.63",
"@electron-forge/maker-squirrel": "^6.0.0-beta.63",
"@electron-forge/maker-zip": "^6.0.0-beta.63",
"electron": "19.0.1"
},
"build": {
"extraResources": [
"py",
{
"from": "python",
"to": "python",
"filter": [
"**/*"
]
}
]
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
<key>NSAppleScriptEnabled</key>
<true/>
<key>com.apple.security.automation.apple-events</key>
<true/>
</dict>
</plist>
This is child.entitlements
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.files.desktop.read-write</key>
<true/>
<key>com.apple.security.automation.apple-events</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
<key>NSAppleEventsUsageDescription</key>
<string>yes</string>
<key>com.apple.security.temporary-exception.apple-events</key>
<true/>
</dict>
</plist>
This is parent.entitlements
If anyone is confused at this same point I found out my problem was actually much simpler than I thought. Check if your info.plist (you can find it by right clicking your finished application and clicking show contents and then it should be in resources) includes NSAppleEventsUsageDescription. If it does not make sure you change electronPackagerConfig to PackagerConfig as that was changed in some version of electron and electronPackagerConfig is now ignored.