4 ms·
On macOS you can read and write to the clipboard with pbcopy and pbpaste: $ ls | pbcopy $ pbpaste > out.txt You can also put this in a function in or
by TheAceOfHearts 6y ago
On macOS you can read and write to the clipboard with pbcopy and pbpaste:
$ ls | pbcopy
$ pbpaste > out.txt
You can also put this in a function in order to get the path of the frontmost Finder window:
osascript 2>/dev/null -e '
tell application "Finder"
return POSIX path of (target of window 1 as alias)
end tell'
Get the current Finder selection:
osascript 2>/dev/null -e '
set output to ""
tell application "Finder" to set the_selection to selection
set item_count to count the_selection
repeat with item_index from 1 to count the_selection
if item_index is less than item_count then set the_delimiter to "\n"
if item_index is item_count then set the_delimiter to ""
set output to output & ((item item_index of the_selection as alias)\'s POSIX path) & the_delimiter
end repeat'
- jgwil2 6y agoAlso, for quick formatting a blob of JSON you've copied: pbpaste | json_pp | pbcopy
- michaelmcmillan 6y agoOn MacOS you can also drag-and-drop a file from Finder onto your terminal and it will type out the full path for you.
- TheAceOfHearts 6y agoYou can also select one or more files and use the hotkey Command + Option + C to "Copy N items as Pathname", which copies the full pathname of each item to your clipboard.
- Tsiklon 6y agoWonderful! I didn't know that it was possible to copy the file path of an arbitrary selection, thanks!
- laacz 5y agoOn Windows I use alias: 'alias pbcopy="clip.exe"' for consistency as I use Mac and Windows daily. ps auxw | pbcopy # After alias works on WSL too.