I’m working on an extension for Alfred that uses touch to create a new file in the currently selected folder in Finder and then copies the path to the new file. As I wasn’t sure if there was a command that could copy the path to this newly created file, I use find to locate the file which works great. I then use pbcopy to copy the path to my clipboard. The format of the path that gets copied is /Users/doug/Desktop//me.md.
I would like to replace /Users/doug with ~ and replace the // between Desktop & me.md with / so the final path is ~/Desktop/me.md.
If it helps, here is my entire script I’m using in Alfred:
folder=`osascript -e 'tell application "Finder" to set theFolder to POSIX path of (target of window 1 as alias)'`
cd "$folder"
touch {query}
find "$folder" -maxdepth 1 -mmin -1 -name "*.md" | pbcopy
The {query} field is replaced with what is typed in Alfred which, in this case, will be the file name of the newly created file.
You can do this easily using sed: