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 ‘folder name or filename with extension’
open command can be used to open a file, folder or URL. Some of the ways you can use the command in this respect –
open -b com.apple.TextEdit 'path to TextFile.txt'opens the document in the application specified (in this case, TextEdit).
open https://www.google.com/opens the URL in the default browser.
In Bash, before inserting space while defining file or folder names, we use a backslash
\ to separate the characters. This will prevent the shell interpreter from interpreting the space as a separator and assuming they were two different arguments. Hence, if the path is
New Folder/myFile we write it as
New\ Folder/myFile or use single quotes as
'New Folder/myfile' instead.