Got one of these in an email

\\fileServer\documents\project\folder

but need one of these

//fileServer/documents/project/folder

and finally one of these to open the connection

open smb://fileServer/documents/project/folder

I find opening paths to the pc network incredibly irritating especially when i get an email from a PC user containing a path to a network that i can't click to open. So i figured given i'm often in Terminal that i should be able to do some sort of shell script to help speed things up.

I asked around and someone suggested "sed" might help so i set about seeing how i could use this to format the correct file path and open up a connection.

I'd already found out that the "open" command would open a correctly formatted path, using 'smb:', i just had to get the the path in the right format.

The final shell command came out as

emile$ open smb:/$1 | sed 's!\\!\/!g'

I created two shell scripts to execute these, echoPath and openPath. I'll add the step to do this another time.

I finally added a terminal script called openPath, i added this to the /bin folder, though i guess there is probably a better place for it.

>touch /bin/openPath
>sudo pico /bin/openPath

T=smb:\\$1
echo $T | sed 's!\\!\/!g' | sed 's/^/open /' | sh -x

ctrl X to exit, y to save changes

>openPath "\\myserver\folder\folder"
+ open smb://myserver/folder/folder

You should find yourself in Finder with the opening server dialogue connecting.

It's quite in here! Why not leave a response?

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options