By using open, I can open a file via terminal.

For example:

$ open ~/Documents/notes.pdf

opens the file notes.pdf in the Documents folder of my home directory. It shows up as a window. Now I'm wondering:

Is there an opposite terminal command with which I can close the opened window (besides kill <pid>)?

  • Do you want to quit the application or just close the window and leave the application running? – fd0 Jul 31 '16 at 10:45
  • Actually quit the application. But if you know a of closing a window: That would interest me too. – mizech Jul 31 '16 at 11:18

Use AppleScript via osascript

 osascript -e 'quit app "Preview"' 
| improve this answer | |
  • 1
    Only works on apps that have coded for AppleScript. (But that is almost everything from Apple and a good portion of the rest). – WGroleau Jul 31 '16 at 13:44

You must log in to answer this question.

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