7

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

3
  • Do you want to quit the application or just close the window and leave the application running?
    – fd0
    Commented Jul 31, 2016 at 10:45
  • Actually quit the application. But if you know a of closing a window: That would interest me too.
    – mizech
    Commented Jul 31, 2016 at 11:18
  • @Thinkr How do you know which application to close after running open some.pdf?
    – nohillside
    Commented May 12, 2023 at 15:13

1 Answer 1

9

Use AppleScript via osascript

 osascript -e 'quit app "Preview"' 
1
  • 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
    Commented Jul 31, 2016 at 13:44

You must log in to answer this question.

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