Sample Header Ad - 728x90

How do I copy multiple files to macOS's clipboard programmatically?

1 vote
1 answer
1535 views
I ultimately want to have a bash function to-clipboard which gets file paths and copies the files to the clipboard. Using other scripting languages as helpers is okay. I currently have this for copying a single file: file-to-clipboard() { osascript \ -e 'on run args' \ -e 'set the clipboard to POSIX file (first item of args)' \ -e end \ "$@" } There is this Applescript that supposedly can copy multiple files, but I don't like it at all: set f to {(POSIX file "/path/to/a/folder/a.png"), (POSIX file "/path/to/another/folder/b.png")} tell application "Finder" try -- to delete any old temp folder delete folder "AS_mailCopy" of (path to temporary items) end try set tmp to make new folder at (path to temporary items) with properties {name:"AS_mailCopy"} duplicate f to tmp select files of tmp activate tell application "System Events" to keystroke "c" using command down delete tmp end tell Related question: https://apple.stackexchange.com/questions/66459/copying-files-to-the-clipboard-using-applescript
Asked by HappyFace (712 rep)
Oct 10, 2018, 04:47 PM
Last activity: Mar 15, 2025, 02:10 PM