30 Mac Terminal Commands to Access Hidden Features

Last Updated: September 29, 2016

Everyone loves hidden features. There’s a reason we call them “Easter Eggs“, it’s like receiving a present from your device. Hidden features may seem gimmicky, but, they can be incredibly productive as well.

The Terminal application in your Mac is a window to the internal working of the system, and it can allow you to change a lot of settings, and access a multitude of features, if you know how to do it. In this article, I’m going to introduce you to some neat commands that will allow you to access a ton of hidden features and capabilities on your Mac.

Note: Some changes might need a restart (or at least a log out, log in) to take effect, especially the ones where we are editing default values.

1. Create Disk Image From Folder Contents

If nothing else, disk images can be incredibly useful to keep files as a restorable image that you can restore on will. It’s something like TimeMachine. The command you need to create a disk image from the contents of a folder is:

hdiutil create -volname "VolumeName" -srcfolder /path/to/folder -ov diskimage.dmg

I have a folder called Beebom, where I save all the screenshots for the various articles I write. Let’s create a disk image from that:

hdiutil create -volname "BeebomImage" -srcfolder ~/Beebom -ov Beebom.dmg

mac commands hidden feature 1

2. Burn Disk Images to DVD

If your Mac has a DVD drive, or if you use an external DVD RW drive, you can burn images to a DVD using the command line. It’s a simple one line command:

hdiutl burn /path/to/image

If I was to burn the Beebom.dmg image on a DVD, I would use the command as:

hdiutl burn ~/Beebom.dmg

Note: This command works for .dmg, .iso and .img files.

3. Write Disk Image to Volume

You can write the data in a disk image to a Volume. You’ll have to format the volume first, though. The command is:

sudo asr -restore -noverify -source /path/to/image -target /Volumes/volumeName --erase

To illustrate, I first created a blank image formatted as ExFAT into which I would restore the Beebom.dmg data. This was accomplished using:

hdiutil create -megabytes 30 -type UDIF -fs ExFAT ~/BlankDisk.dmg

This created a blank, mountable disk that I could freely format without losing data. Remember to mount this disk by double clicking on it. Then, navigate to “/Volumes/” by doing the following:

1. Open Finder

2. Press Command + Shift + G

3. Type /Volumes/ and press Enter

Next, I ran the following command to write the contents of Beebom.dmg to the BlankDisk.dmg volume.

sudo asr -restore -noverify -source ~/Beebom.dmg -target /Volumes/Untitled/ --erase

mac terminal commands writing to disk

4. Convert Files To HTML

If you have a .txt, .rtf or even a .doc/.docx file, you can easily convert it into the html format using a simple Terminal command.

textutil -convert html file.ext

Simply replace the “file.ext” with the path to the file you want to convert and press Enter.

I created a sample beebom.rtf file to convert into its HTML equivalent.

textutil -convert html ~/beebom.html

Note: This command can convert documents to multiple formats such as txt, rtf, rtfd, html, doc, docx, odt, or webarchive. 


5. Add a Recent Apps Stack to Dock

The dock provides you with quick access to multiple apps, as well as Downloads and Trash. However, using a simple command can let you add another stack to the Dock for your Recent Applications. The command to achieve this is a bit long and may be difficult to understand.

defaults write com.apple.dock persistent-others -array-add \
'{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }' && \
killall Dock

This enables the “Recent Applications” stack on your dock. Also, perform a “double-finger tap” on this stack and you can choose from options such as “Recent Applications”, “Recent Documents”, “Recent Servers”, etc.

mac commands recents app dock

6. Add a Spacer Tile to Dock

You can also add a blank tile, or a spacer tile (as it is called), to the dock. This can help you to increase the space between multiple icons on the dock to give them a more spread out and neat look, if you want. The command to add a spacer tile to your dock is similar to the command for adding a “Recent Apps” stack.

defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}' && \
killall Dock

mac commands spacer tiles

7. Prevent App Icons on Dock From Bouncing

I find it very annoying when an app icon starts bouncing up and down on the dock, trying to get my attention. Yes, it only does that when it actually requires attention, but it can get really annoying. If you would like to stop the app icons from bouncing on the dock, just use the following command to prevent the behaviour.

Note: This command doesn’t stop the icon from bouncing when you launch it, only when it bounces to attract attention.

defaults write com.apple.dock no-bouncing -bool false && \
killall Dock

If you find that you miss those bouncing icons, or if you just wanted to try this out for once, you can simply use the following command to enable bouncing again.

defaults write com.apple.dock no-bouncing -bool true && \
killall Dock

8. Reset Dock

Maybe you have added a lot of applications to your Dock, adjusted the size, and rearranged the icons way too much, or maybe you just want your Dock back to the way it was when you first booted up your Mac. Whatever your reasons may be, the command to accomplish this is very simple.

All you need to do, is run the following command in Terminal, and your Dock will reset back to its original settings.

defaults delete com.apple.dock && \
killall Dock

9. Hide a File or Folder

There are multiple reasons to want to hide a file or a folder. For one, it may have confidential data that you don’t want others to see.

You might know that files with a “.” prepended to their name, are hidden by default. However, you can’t just prepend a “.” to a file or a folder. Try it out, Finder will give you a warning and the operation will fail.

Also, if someone wants to check for hidden folders on your directory, they will most probably look for files with a “.” prepended to their names, anyway. So why not hide your personal files and folders in a better manner?

All it takes is a simple command.

chflags hidden /path/to/file/folder

If you want to unhide these files or folders, all you need to do is replace “hidden” with “nohidden” in the command above.

10. Show/Hide Hidden Files and Folders

There are some directories and files that your Mac keeps hidden from you in Finder. The reason is simple; these are the files and folders that a casual user would normally not require access to. However, if you ever do need to access these hidden folders, all you need to do is edit one of the default values for Finder, and this can be done with the following command:

defaults write com.apple.finder AppleShowAllFiles true

Intuitively, the command to hide all those files and folders simply changes the command to say “false” instead of “true”

Once you have executed this command, you will need to relaunch Finder. To do this, follow the steps given below:

  • Locate the “Finder” icon on your Dock.
  • Press “option” and tap on the icon with two fingers.
  • From the context menu, select “Relaunch”


11. Show/Hide Full Path in Finder Title Bar

If you have ever used the Terminal to modify, access or transfer files, you will know that finding the “path” of files is very important to point the Terminal to the correct file.

Normally, you’ll have to select the file in Finder and use the “Get Info” option to find the path to that file. However, Finder can be set to display the entire path of the current directory you’re in, by executing one simple command.

defaults write com.apple.finder _FXShowPosixPathInTitle -bool true

Your finder will now show the complete path to the current directory in its title bar.

To turn this feature off, use the following command:

defaults write com.apple.finder _FXShowPosixPathInTitle -bool false

12. Enable The Option to Quit Finder

Finder is app that doesn’t show a “Quit Finder” item in its menu, doesn’t respond to “Command + Q” hotkeys and basically looks invincible. The option to quit Finder is actually just hidden and can be exposed with a simple command.

defaults write com.apple.finder QuitMenuItem -bool true && \
killall Finder

If you want to hide the option again, simply use the following command:

defaults write com.apple.finder QuitMenuItem -bool false && \
killall Finder

quit finder

13. Disable Smooth Scrolling

Smooth scrolling is actually a boon. It helps the entire UI look more fluid and allows the user to interact in a much better manner with the UI. On older Macs, however, smooth scrolling can burn more bridges than it helps build.

Older Macs might not have enough GPU horsepower to effectively apply smooth scrolling effects to the UI. Thankfully, smooth scrolling can be disabled.

This command will disable smooth scrolling on your Mac

defaults write NSGlobalDomain NSScrollAnimationEnabled -bool false

To enable it again, just replace “false” with “true”

14. Show/Hide Desktop Icons

Have you ever had to screen-share with someone over applications like “FaceTime” and “TeamViewer”? Most people would have used one or the other screen sharing service, at least once. However, if you’re like me, your desktop probably gets cluttered all the time, and obviously, you’d not want the other person to see that clutter. That other person could be your boss, and you’d not want them to see how unorganised your desktop usually is, would you?

Instead of spending a long time filtering out the clutter, and sorting files into directories, you can simply use the following command to hide the icons from your desktop; making it perfect for screen sharing, presentations, and basically any task where another person might see your desktop and judge you for your poor organisational skills.

The command to hide icons from your desktop is:

defaults write com.apple.finder CreateDesktop -bool false && \
killall Finder

Of course, once you’re done with the task at hand, you’d like to get all your desktop mess back on your, well, desktop. To do this, simply run the following command:

defaults write com.apple.finder CreateDesktop -bool true && \
killall Finder


15. Show/Hide Path Bar in Finder

The path bar does exactly what its name suggests: it displays the path to the current working directory that you’re in. Instead of enabling the Finder “title bar” to display the path, why not use the “path bar” itself? After all, this is what it’s meant to do.

The command defaults write com.apple.finder ShowPathbar -bool true enables a “path bar” in Finder.

You can also hide the “path bar” if you want, just replace “true” with “false” in the command given above.

16. Open Folders, URLs, Files, Applications

You can open folders, files, URLs, even Applications, directly from the Terminal app. This is especially useful if you’re writing a script to access a file, folder or a URL.

The command, intuitively, is “open”. The arguments you pass to “open” helps it to decide what you’re asking it to open.

For example, to open a folder, the command will be:

open /path/to/folder

If you have navigated to some directory inside the Terminal, and you want to open that directory in Finder, simply use the following command:

open .

Note: There is a “.” after open, this “.” implies that you’re asking it to open the folder that it is currently in.

You can also open URLs.

open "https://github.com" will open GitHub in your default browser.

17. Prevent Mac From Sleeping

There exists a plethora of applications that are directed at preventing your Mac from sleeping for a user specified period of time, and they work. But why install a third-party app when you can use the Terminal to achieve the same functionality?

There’s a command line utility built-in into Mac, called “caffeinate”. Cleverly named, as caffeine is known to prevent sleepiness, caffeinate can be used to set a time for which your Mac will not sleep.

The command is simple enough.

caffeinate -u -t time_in_seconds

So, if you wanted to prevent your Mac from sleeping for, say, 1 hour, the command will become:

caffeinate -u -t 3600

18. Put Display to Sleep After Specified Time

On the other hand, you might want to set your Mac so that it puts the display to sleep after a time specified by you.

You can use the “Power Manager” to accomplish this. The command is simple, but requires “super user” access to run, as it changes power settings.

sudo pmset displaysleep time_in_minutes

Say you want your Mac to sleep after 5 minutes of inactivity, the command to enable this will be:

sudo pmset displaysleep 5

19. Set Mac to Automatically Restart if Frozen

Macs are wonderful machines. They barely ever freeze, thanks to excellent management of resources by OS X that tries to put the user first. However, every now and then, even a Mac stops responding. The reasons for which may be one of many; the point is, at that instance, all you can do is hold down the power button until your Mac powers off, and then restart it.

Wouldn’t it be better if you could just set your Mac to automatically restart whenever it freezes? I think it would.

All you need to do, is run sudo systemsetup -setrestartfreeze on and your Mac will automatically restart whenever (if, at all) it freezes. Neat, right?

Note: I couldn’t actually test this, because I was obviously not going to freeze my Mac on purpose, but the documentation contains this feature, so it should work.

20. Disable Autocorrect on Keyboard

Autocorrect is one of those features that can be both a life saving, and a terribly annoying tool. Everyone has varying opinions on autocorrect, which is perfectly fine. If you think autocorrect helps you more than it annoys you, you’re golden because Mac keyboards come with autocorrect turned on, by default. If, however, you’re like me, and you don’t find autocorrect useful enough, you can disable it on your keyboard with a simple command.

defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false

21. Disable the Default Long Press Action for Keys

Everyone of us has gone crazy at times and wanted to type messages that use unnecessary repeated letters like “hiiiiiiii”, or “yayyyy”. Don’t lie, I know you have, too. The problem, simply, is that the keyboard on Mac behaves like one would expect the keyboard for a mobile device to behave. Long pressing a key comes up with a menu for accented characters. Some might find that useful, I find it unimportant. Sure, on an iPhone long pressing leads to accented characters, but should it really be that way on a laptop? I don’t think so.

Fortunately, there’s a way to stop this iOS like behaviour from leaking into our Macs.

defaults write -g ApplePressAndHoldEnabled -bool false

It’s recommended to log out and log in, in order for the changes to take effect.

22. Adjust Key Repeat Rate

So you changed the default long press behaviour for your Mac, and you tried to repeat letters by long pressing on the key, but it’s just too slow (or maybe, too fast)? All you need to do is adjust the key repeat rate. Set the value to whatever you prefer, you’ll have to test out a couple of values to find a good match.

defaults write NSGlobalDomain KeyRepeat -int 0.02

This will set a very fast key repeat rate. You can adjust the value to your preference.

23. Convert Audio File to iPhone Ringtone

iPhones use the .m4r format for ringtones, and if you have ever wanted to set your favourite song as your ringtone, you’re out of luck until you convert the file to the .m4r format. Fortunately, you can do this very easily using the Terminal.

afconvert input.mp3 ringtone.m4r -f m4af

This command takes an input.mp3 file, converts it into .m4r format and saves it with the name “ringtone.m4r”

24. Create Audiobook from Text File

This is a fun one. One simple command on the Terminal, and you can convert any text file into an Audiobook, complete with proper pauses at punctuation marks.

The command itself, is: say -v Alex -f /path/to/file.txt -o "outputfile.m4a"

Note: This command creates the audiobook in the “Alex” voice, OS X has a lot of available voices to choose from, you can find out more by running say -v ? in the Terminal.

25. Disable Sound on Boot

Yes, you can press a key while you power your computer on, to prevent it from making the iconic “chime”, but you have to do that every time you start your Mac. Why not disable it completely? All you need to do, is run the following command:

sudo nvram SystemAudioVolume=" "

26. Show WiFi Network Password

Often times, it so happens that I have my Mac connected to a WiFi network and I want to connect my phone, as well. Alas, I don’t remember the password. I could guess it, sure, but I could also ask my Mac to just tell me. It seems to me, that the latter is a much more efficient way to approach this particular problem.

security find-generic-password -D "AirPort network password" -a "SSID" -gw

That is the command you need to run in the Terminal. Obviously, replace “SSID” with the name of the WiFi network you want to find the password for.

Note: This command can only show the passwords to WiFi networks that your Mac has connected to, at least once. This is not a tool to crack WiFi passwords.


27. Generate Secure Passwords

Secure passwords are hard to create and harder to remember. Well, I can at least help you solve half of that problem. The other half – the remembering part – well, that’s on you. You could just write it down somewhere safe, you know.

Terminal can help you generate strong passwords using this command:

date | md5


28. Take Delayed Screenshots

Ever wanted to take a delayed screenshot? I personally haven’t ever needed to, but maybe you have. There has to be someone who uses this, because there exist third-party apps that allow this. Maybe they want to create a time-lapse of their screens, but I digress. I’m here to tell you that you don’t need those third-party apps in order to take delayed screenshots.

All you need is, you guessed it, the Terminal, and the following command:

screencapture -T 3 -t jpg -P delayedpic.jpg

This will take a screenshot after 3 seconds, and save it as “delayedpic.jpg” on your computer.

29. Change Default Screenshot Format

Here, at Beebom, we use JPEG screenshots throughout the website; Macs take screenshots in PNG, by default. This caused a major difficulty: I had to export every screenshot to a JPEG format before I could use it on the website. However, it also caused me to look for a solution, and it turns out, the solution is a command; and a simple one at that.
defaults write com.apple.screencapture type "jpg"

This command will save me countless hours of converting screenshots to JPEGs and then uploading them on the website.

30. Play iOS Charging Sound When MagSafe is Connected

To be honest, this is more of a gimmick; but it could be useful if the light on your MagSafe connector has gone bad, and doesn’t work. Note that I said it “could” be useful. I mean, you can still see the battery icon to check if your laptop is charging or not, but whatever. This is a cool hidden feature, nonetheless, and I’m covering it.

defaults write com.apple.PowerChime ChimeOnAllHardware -bool true && \
open /System/Library/CoreServices/PowerChime.app

You can turn it off, as well.

defaults write com.apple.PowerChime ChimeOnAllHardware -bool false && \
open /System/Library/CoreServices/PowerChime.app

SEE ALSO: 25 Essential Menu Bar Applications for Mac

Explore, Learn, Be Productive

These hidden features are not an exhaustive list. I don’t claim to know everything the Terminal can do, but this article can give you some idea about the advantages of exploring the Terminal and its commands. Try out the features I have explained in this article, and comment below, explaining your experience with these commands.