History
I was tired to have to make new scripts everytime I need to do a quick thing on some files or test a new library.
Function
Adds a menu entry to launch Docker-based Jupyter notebooks directly from KDE’s file manager. The notebook runs in a container with the current directory mounted.
Setup
Create the KDE service menu directory:
mkdir -p ~/.local/share/kio/servicemenus/
Create two files:
- Service menu definition (
~/.local/share/kio/servicemenus/jupyter-notebook.desktop
):
[Desktop Entry]
Type=Service
MimeType=inode/directory;
Actions=startNotebook;
X-KDE-Priority=TopLevel
[Desktop Action startNotebook]
Name=New Jupyter Notebook
Icon=text-x-python
Exec=konsole -e ~/.local/bin/start-notebook.sh
- Launcher script (
~/.local/bin/start-notebook.sh
):
#!/usr/bin/env bash
# Function to check if port is in use
port_in_use() {
lsof -i:$1 >/dev/null 2>&1
return $?
}
# Find first available port starting from 8888
port=8888
while port_in_use $port; do
((port++))
if [ $port -gt 8899 ]; then
echo "No available ports in range 8888-8899"
exit 1
fi
done
# Start container with available port
container_id=$(docker run --rm -d -p $port:8888 -v "$(pwd)":/home/jovyan/work jupyter/scipy-notebook)
# Wait for container to start and get URL
max_attempts=10
attempt=0
while [ $attempt -lt $max_attempts ]; do
url=$(docker logs $container_id 2>&1 | grep -o "http://127.0.0.1:8888/lab?token=[^[:space:]]*" | tail -n1)
if [ ! -z "$url" ]; then
# Replace default port with our actual port
url=${url/8888/$port}
xdg-open "$url"
exit 0
fi
sleep 1
((attempt++))
done
echo "Failed to start Jupyter notebook"
exit 1
Refresh KDE’s service menu cache:
kbuildsycoca6
Features
- Port selection: 8888-8899 (auto-detects what’s used)
- Directory mounting (mounts current directory into work)
- Local-only access
- Browser auto-launch
Planned Features
- requirements.txt integration
- Persistent containers? (currently ephemeral)
- Environment configurations
- Clean-up
TL;DR
Launch Jupyter notebooks from any directory through the right-click menu.
For more details about KDE service menus, see the KDE Development documentation. KDE is great you should use it and give them money.