Category filter

Script to hide/unhide files and folders on macOS devices

On a Mac, certain system files and folders are hidden by default. This is to protect the system files from accidental/unwanted modifications by users. But, if you want to hide more sensitive files/folders present on your devices or make them unavailable to the user unless they are useful, or unhide a file you previously hid, you can execute these scripts using the Execute Custom Script action.

Scripting language – Bash

File extension – .sh

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Hide file/folder

For example, to hide a file named Notes.txt stored at /Users/admin/Desktop, deploy the following script.

Although they remain present on the device, the hidden files are neither accessible to the user nor do they appear in Finder.

Similarly, to hide a folder named My Documents stored at /Users/admin/Desktop deploy the following script.

Unhide file/folder

Note:


The script cannot be used to unhide system files or folders that are hidden by default.

For example, to unhide a file named Notes.txt stored at /Users/admin/Desktop, deploy the following script.

Similarly, to unhide a folder named My Documents stored at /Users/admin/Desktop, you can deploy the following script.

Reveal all hidden files/folders

You can reveal all hidden files and folders on your device by deploying the following script. However, the icons of the hidden files and folders appear faded.

Note:


The script will also reveal system files and folders that are hidden by default.

This will reveal all hidden files and folders, allowing the currently logged-in user to access them.

Hide all revealed hidden files/folders

Once revealed, if you would like to hide all the revealed files and folders again, you can do so by deploying the following script.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository