Is it possible? I would like something which is the opposite of the command open file_or_folder_name. I have searched on the web but I got no results.


The open command opens a file in the default application for that file. To close the file in that application, you will need to control the application to close the file. This will depend on what the application is—not all applications support AppleScript control for example and quitting the app is not the same as closing a file.


You can use osascript to run an applescript which closes a window in a certain app:

osascript -e "tell application "$1"                                             
close window 1                                                                  
end tell"

Save this shell script as "closewindow" and do chmod +x closewindow.

This way by running:

$ closewindow appname

you will close window 1 of appname.

There also must be a way to get the number of open windows and close the one that was opened last, but I can't find that right now


You cannot directly close a file, this is a responsibility of the application.

If quitting the application is an option you can use kill or pkill to quit it.

Or you can try to use Apple Script to close an individual window. See How do I close a window from an application, passing the file name? on SuperUser

You must log in to answer this question.

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