feat: Add macOS directory selection support via AppleScript
This commit is contained in:
parent
70e3af157e
commit
caf7844972
@ -173,17 +173,32 @@ with col1:
|
|||||||
with col_src1:
|
with col_src1:
|
||||||
if st.button("Browse", key='source_browse'):
|
if st.button("Browse", key='source_browse'):
|
||||||
try:
|
try:
|
||||||
import tkinter as tk
|
if platform.system() == "Darwin": # macOS
|
||||||
from tkinter import filedialog
|
try:
|
||||||
root = tk.Tk()
|
result = subprocess.run(
|
||||||
root.withdraw()
|
['osascript', '-e', 'choose folder with prompt "Select Source Directory"'],
|
||||||
root.wm_attributes('-topmost', 1)
|
capture_output=True,
|
||||||
path = filedialog.askdirectory(title="Select Source Directory")
|
text=True
|
||||||
if path:
|
)
|
||||||
st.session_state['source_dir'] = path
|
if result.returncode == 0:
|
||||||
st.session_state['source_dir_input'] = path
|
path = result.stdout.strip()
|
||||||
st.experimental_rerun()
|
st.session_state['source_dir'] = path
|
||||||
root.destroy()
|
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:
|
except Exception as e:
|
||||||
st.error(f"Error selecting directory: {str(e)}")
|
st.error(f"Error selecting directory: {str(e)}")
|
||||||
|
|
||||||
@ -204,17 +219,32 @@ with col1:
|
|||||||
with col_dest1:
|
with col_dest1:
|
||||||
if st.button("Browse", key='dest_browse'):
|
if st.button("Browse", key='dest_browse'):
|
||||||
try:
|
try:
|
||||||
import tkinter as tk
|
if platform.system() == "Darwin": # macOS
|
||||||
from tkinter import filedialog
|
try:
|
||||||
root = tk.Tk()
|
result = subprocess.run(
|
||||||
root.withdraw()
|
['osascript', '-e', 'choose folder with prompt "Select Destination Directory"'],
|
||||||
root.wm_attributes('-topmost', 1)
|
capture_output=True,
|
||||||
path = filedialog.askdirectory(title="Select Destination Directory")
|
text=True
|
||||||
if path:
|
)
|
||||||
st.session_state['dest_dir'] = path
|
if result.returncode == 0:
|
||||||
st.session_state['dest_dir_input'] = path
|
path = result.stdout.strip()
|
||||||
st.experimental_rerun()
|
st.session_state['dest_dir'] = path
|
||||||
root.destroy()
|
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:
|
except Exception as e:
|
||||||
st.error(f"Error selecting directory: {str(e)}")
|
st.error(f"Error selecting directory: {str(e)}")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user