Skip to content

Instantly share code, notes, and snippets.

@akvedi
Created July 19, 2024 04:24
Show Gist options
  • Save akvedi/477b84cb2a22e90d1e9b7af4587c3c1b to your computer and use it in GitHub Desktop.
Save akvedi/477b84cb2a22e90d1e9b7af4587c3c1b to your computer and use it in GitHub Desktop.
A bash script to automatically open Nautilus with the correct sftp path for gsconnect gnome.

GSconenct uses incomplete path to mount the sftp on some devices. Thus giving an error when accessed.

ss

This bash script will automatically open the sftp folder with the correct path.

How to use it

  • Make a new empty file
  • Copy the below script and paste it
  • save the file to appropriate location
  • Right click on the file and go to properties and select Execute as programm.
  • Make sure gsconnect sftp is mounted
  • Right click on the file and select Run as programm
#!/bin/bash
# A script to open GSconnect sftp folder with correct path

# Define the path to the GVFS folder
gvfs_path="/run/user/1000/gvfs"

# Find the folder that matches the pattern "sftp:host=*,port=*"
folder=$(find "$gvfs_path" -type d -name "sftp:host=*,port=*" | head -n 1)

if [ -z "$folder" ]; then
  echo "No matching folder found."
  exit 1
fi

# Extract host and port from the folder name
regex="sftp:host=([^,]*),port=([0-9]*)"
if [[ $folder =~ $regex ]]; then
  host=${BASH_REMATCH[1]}
  port=${BASH_REMATCH[2]}
else
  echo "Failed to extract host and port from folder name."
  exit 1
fi

# Construct the sftp URL
sftp_url="sftp://$host:$port/storage/emulated/0"

echo "Opening $sftp_url in Nautilus..."

# Open the sftp URL in Nautilus
nautilus "$sftp_url" &
You can also make a desktop file for this script to launch it with double click

This script works with Nautilus but can be easily modified to work with other file managers.

@philippe-r972
Copy link

Thanks so much. All works fine now

@akvedi
Copy link
Author

akvedi commented Aug 9, 2024

Thanks so much. All works fine now

You're welcome! Glad to hear that it worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment