diff --git a/src/streamlit_app.py b/src/streamlit_app.py index 830acd2..dc638a0 100644 --- a/src/streamlit_app.py +++ b/src/streamlit_app.py @@ -173,17 +173,32 @@ with col1: with col_src1: if st.button("Browse", key='source_browse'): try: - import tkinter as tk - from tkinter import filedialog - root = tk.Tk() - root.withdraw() - root.wm_attributes('-topmost', 1) - path = filedialog.askdirectory(title="Select Source Directory") - if path: - st.session_state['source_dir'] = path - st.session_state['source_dir_input'] = path - st.experimental_rerun() - root.destroy() + if platform.system() == "Darwin": # macOS + try: + result = subprocess.run( + ['osascript', '-e', 'choose folder with prompt "Select Source Directory"'], + capture_output=True, + text=True + ) + if result.returncode == 0: + path = result.stdout.strip() + st.session_state['source_dir'] = path + st.session_state['source_dir_input'] = path + st.experimental_rerun() + except Exception as e: + st.error(f"Error using AppleScript: {str(e)}") + else: # Windows or Linux + import tkinter as tk + from tkinter import filedialog + root = tk.Tk() + root.withdraw() + root.wm_attributes('-topmost', 1) + path = filedialog.askdirectory(title="Select Source Directory") + if path: + st.session_state['source_dir'] = path + st.session_state['source_dir_input'] = path + st.experimental_rerun() + root.destroy() except Exception as e: st.error(f"Error selecting directory: {str(e)}") @@ -204,17 +219,32 @@ with col1: with col_dest1: if st.button("Browse", key='dest_browse'): try: - import tkinter as tk - from tkinter import filedialog - root = tk.Tk() - root.withdraw() - root.wm_attributes('-topmost', 1) - path = filedialog.askdirectory(title="Select Destination Directory") - if path: - st.session_state['dest_dir'] = path - st.session_state['dest_dir_input'] = path - st.experimental_rerun() - root.destroy() + if platform.system() == "Darwin": # macOS + try: + result = subprocess.run( + ['osascript', '-e', 'choose folder with prompt "Select Destination Directory"'], + capture_output=True, + text=True + ) + if result.returncode == 0: + path = result.stdout.strip() + st.session_state['dest_dir'] = path + st.session_state['dest_dir_input'] = path + st.experimental_rerun() + except Exception as e: + st.error(f"Error using AppleScript: {str(e)}") + else: # Windows or Linux + import tkinter as tk + from tkinter import filedialog + root = tk.Tk() + root.withdraw() + root.wm_attributes('-topmost', 1) + path = filedialog.askdirectory(title="Select Destination Directory") + if path: + st.session_state['dest_dir'] = path + st.session_state['dest_dir_input'] = path + st.experimental_rerun() + root.destroy() except Exception as e: st.error(f"Error selecting directory: {str(e)}")