appium / appium-mac2-driver

Next-gen Appium macOS driver, backed by Apple XCTest
Apache License 2.0
115 stars 24 forks source link

How to enable insecure feature 'apple_script' in Python? #265

Closed MagdelineNg closed 5 months ago

MagdelineNg commented 5 months ago
import subprocess

from appium import webdriver as appium_webdriver
from appium.options.mac import Mac2Options
from appium.webdriver.appium_service import AppiumService
from appium.webdriver.common.appiumby import AppiumBy

APPIUM_PORT = '4723'
APPIUM_HOST = '127.0.0.1'
BUNDLE_ID = "com.apple.app1"

options = Mac2Options()
options.bundle_id = BUNDLE_ID
options.show_server_logs = True
options.system_port = 10100
options.wait_for_quiescence = False
appium_service = AppiumService()
appium_service.start()

driver = appium_webdriver.Remote(f"http://{APPIUM_HOST}:{APPIUM_PORT}", options=options)

#open system preferences with the other app still open
driver.execute_script('macos: activateApp', {'bundleId': 'com.apple.systempreferences'})
with open(f"{str(pathlib.Path(__file__).parent)}/settings.xml", "w") as ps:
    ps.write(driver.page_source)
driver.execute_script("macos: appleScript", "do shell script \"echo hello\"")

Error displayed: Original error: Potentially insecure feature 'apple_script' has not been enabled. If you want to enable this feature and accept the security ramifications, please do so by following the documented instructions at http://appium.io/docs/en/2.0/guides/security/

The documentation only shows the flag from command line, but I want to set it under options in my code. Which options attribute is it?

Edit: I am thinking of using Apple Script to change "display" settings in MacOS System Settings. However, I was wondering if it is possible to use macos:activateApp to open MacOS System settings and automate some actions in the settings app. Is it possible for Mac2 driver to automate macos settings app?

jlipps commented 5 months ago

For security reasons, you must set security flags from the CLI. This is the only way to ensure that only sysadmins have the ability to set security policies.