MacOS – n inverse command to open in the Terminal

macosterminal

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

Best Answer

Use AppleScript via osascript

 osascript -e 'quit app "Preview"'