I would like to

  • copy a file to the clipboard in terminal (as a reference like Finder does it) and then
  • when writing an email, paste it into Mail as an attachment (CMD + V).

I posted an example solution below but I'd prefer a script that does not need to open Finder.

1 Answer 1


The following script works but it needs to open (and close) a Finder window.

Save this to maccopy:

on run args
  set theFile to (POSIX file (first item of args)) as alias
  tell application "Finder"
      set selection to {}
      reveal theFile
  end tell
  delay 1
  tell app "System Events"
      keystroke "c" using command down
  end tell
  tell application "Finder"
      close window 1
  end tell
  tell application "iTerm2"
  end tell

and chmod +x maccopy.

Use with maccopy PATH-TO-FILE.


You must log in to answer this question.

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