feat: Improve macOS app chooser functionality and enhance drag operation success criteria
Some checks are pending
Tests & Quality Checks / Test on Python 3.11 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.10 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-2 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-2 (push) Waiting to run
Tests & Quality Checks / Build Artifacts (push) Blocked by required conditions
Tests & Quality Checks / Build Artifacts-1 (push) Blocked by required conditions

This commit is contained in:
claudi 2026-04-14 14:44:32 +02:00
parent cbd8ed0186
commit d6f4140947
3 changed files with 80 additions and 20 deletions

View file

@ -1185,20 +1185,55 @@ class MainWindow(QMainWindow):
if sys.platform == "darwin":
# Prompt for an app and open the file with the selected app.
script = (
"on run argv\n"
"set targetFile to POSIX file (item 1 of argv)\n"
"set chosenApp to choose application\n"
'tell application "Finder" to open targetFile using chosenApp\n'
"end run"
)
result = subprocess.run(
["osascript", "-e", script, file_path],
check=False,
capture_output=True,
text=True,
)
return result.returncode == 0
# Use AppleScript with choose application and open the file.
# This more reliably opens files with chosen applications.
# Use a simple, more direct approach
# Get the chosen app via AppleScript, then use open command
get_app_script = '''choose application with title "Select an application to open the file"'''
try:
# Get the chosen application
app_result = subprocess.run(
["osascript", "-e", get_app_script],
check=False,
capture_output=True,
text=True,
timeout=30,
)
if app_result.returncode != 0:
logger.warning(f"User cancelled app chooser or error occurred: {app_result.stderr}")
return False
# Get the application name (strip whitespace)
chosen_app = app_result.stdout.strip()
if not chosen_app:
logger.warning("No application was selected")
return False
logger.info(f"User selected app: {chosen_app}")
# Now open the file with the chosen app using the 'open' command
open_result = subprocess.run(
["open", "-a", chosen_app, normalized_path],
check=False,
capture_output=True,
text=True,
timeout=10,
)
if open_result.returncode == 0:
logger.info(f"Opened '{normalized_path}' with '{chosen_app}'")
return True
else:
logger.warning(f"Failed to open file with '{chosen_app}': {open_result.stderr}")
return False
except subprocess.TimeoutExpired:
logger.warning("App chooser timed out")
return False
except Exception as e:
logger.warning(f"Error in macOS app chooser: {e}")
return False
logger.warning(f"Open-with chooser not implemented for platform: {sys.platform}")
return False