1

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.)

3

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() {
    IFS=$'\n'
    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? – user3439894 Jul 24 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 at 14:30

You must log in to answer this question.

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