Trim escape characters from file path

automatorfinderterminal

I generate file paths for use in emails by dragging the folder/file in question into Terminal.app then copying & pasting the generated text into an email text.

The copied path with escape sequences:

pCloud\ Drive/SEN\ pCloud/SEN\ Tech\ Team/Clean\ Energy\ WA\ Study\2016/For\ checking/AB\ checks/SEN\ RE\ SWIS\ 2030\ notes\ for\ AB\checks\ -\ Backup\ input\ table\ tab\ \(5.1.16\).docx

needs to become like this:

pCloud Drive/SEN pCloud/SEN Tech Team/Clean Energy WA Study 2016/For checking/AB checks/SEN RE SWIS 2030 notes for AB\checks - Backup input table tab \(5.1.16\).docx

I am looking for a quick way to zap all the occurrences of backslash character escaping the space character. Someone mentioned a Finder trick for doing that, but now I've forgotten it.

I tried to create a Finder Service to do a simple Find & Replace in Automator but couldn't get it done. Automator will allow me to make it appear in Applications under Services (although on my current macOS I don't seem to see that menu, maybe I need to do something to enable it).

How do I accomplish this?

Best Answer

  • Select a file with a right click
  • Hold down the Option key
  • Select the menu item Copy "filename" as Pathname

Note: I believe this only works in El Capitan and above.