I want to paste a file copied by Finder in the terminal. Sth like pbpaste but for binaries. (pbpaste itself just returns the basename of the copied file.)

  • What should happen afterwards, where do you want to paste the file content to?
    – nohillside
    Jul 17, 2019 at 5:55
  • May be related apple.stackexchange.com/questions/362245/…
    – nohillside
    Jul 17, 2019 at 6:26
  • @nohillside I want pastefile DIR to paste the file into DIR.
    – HappyFace
    Jul 17, 2019 at 7:10
  • Something like cp $(pbpaste) DIR then?
    – nohillside
    Jul 17, 2019 at 7:15
  • @nohillside pbpaste just pastes the basename, not the complete path.
    – HappyFace
    Jul 17, 2019 at 7:16

1 Answer 1


One way I can think of doing this is to use a little bit of AppleScriptObjC. It provides access to the various data type representations on the clipboard, and in multiple.

After retrieving the full file paths, these can then be passed to the cp command.

Wrapping this in a bash function declaration:

pastefiles() {
    fs=($( osascript -e "use framework \"Foundation\"
        property this : a reference to the current application
        property NSPasteboard : a reference to NSPasteboard of this
        property NSURL : a reference to NSURL of this
        property pb : a reference to NSPasteboard's generalPasteboard

        property text item delimiters : linefeed

        pb's readObjectsForClasses:[NSURL] options:[]
        (result's valueForKey:\"path\") as list as text" ))

    cp -r "${fs[@]}" "$1"

Usage: pastefiles~/Example/Destination/Path

You can add this to your .bashrc file to have the function available to each new shell session.

  • In macOS 10.15 Catalina, Apple has replace the previous default shell, bash, with zsh.Do you know if this will this work as is if placed in the e.g. users .zprofile or .zshrc file? Jul 24, 2019 at 15:55
  • @user3439894 I don't know, I'm afraid. Not used zsh before. I use FiSh as my default shell.
    – CJK
    Jul 25, 2019 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .