Category filter
Script to open files and folders on Mac
To open a file or folder on a Mac, the user will have to navigate to the location on the Finder application and click on the file or use the context menu ‘Open With’ option to open the file with the relevant application. This method is tedious for the device administrator when managing multiple endpoints and impractical when opening multiple files or folders with the non-default application or even when doing a batch operation. On the other hand, using a script to automate this process is easy, efficient, and effective. This doc includes shell scripts that you can run using Hexnode’s Execute Custom Script action to open files or folders on a Mac remotely.
Scripting language – Bash
File extension – .sh
Open file or folder
The open
command can be used to open a file or folder. Some of the ways you can use the command are:
Open file:
1 2 |
#!/bin/bash open ‘filename with extension and the complete path from root’ |
This script opens the specified file in the default application.
1 2 |
#!/bin/bash open -b com.apple.TextEdit 'path to TextFile.txt' |
This script opens the file in the required application (in this case, TextEdit). Bundle identifier -b
is used to mention the application on which the file has to be opened.
Open folder:
1 2 |
#!/bin/bash open ‘folder name with the complete path from root' |
This script opens the folder in the Finder app.