Apple

macOS Command Line – Part 4: App Control, Spotlight, Clipboard and Extended Attribute

The macOS Terminal is a powerhouse for system management. From opening apps to leveraging Spotlight and managing clipboard tasks, these commands can optimize your workflow. Here's a breakdown of essential…

2 min read TexArxs

The macOS Terminal is a powerhouse for system management. From opening apps to leveraging Spotlight and managing clipboard tasks, these commands can optimize your workflow. Here’s a breakdown of essential commands every macOS user should know.

Opening Applications and Files

The open command is your gateway to launching apps, files, and URLs directly from the terminal.

Application Commands

  • Open an Application

open -a Calculator

  • Start a New Instance of an App

open -n -a Calendar

  • Launch an App Fresh Without Previous State

open -F -n -a Mail


File Commands

  • Open a File in TextEdit

open -e report.docx

  • Reveal File in Finder

open -R example.pdf

  • Open Finder in Current Directory

open ./Projects


Spotlight Commands

Spotlight search can be controlled from the terminal using mdfind and mdutilcommands.

  • Search for PDFs

mdfind -name print.pdf

  • Limit Search to a Directory

mdfind -onlyin ~/Downloads -name invoice.pdf

  • Enable/Disable Spotlight Indexing

mdutil -i on ~/Documents

mdutil -i off ~/Desktop


Extended File Attributes

Display and manipulate extended attributes. This can also be used to clear the quarantine from downloaded file.

  • List Attributes

xattr -l ~/Documents/summary.txt

  • Remove Quarantine Attribute

xattr -d com.apple.quarantine ~/Downloads/Firefox.dmg

  • Clear All Attributes

xattr -c ~/Pictures/myphoto.jpg


Clipboard Management

Efficiently handle clipboard tasks, including text, command outputs, and file contents, directly from the terminal.

Copy and Paste Commands

  • Copy Text to Clipboard

echo “Hello, World!” | pbcopy

  • Copy Command Output to Clipboard

date | pbcopy

  • Copy File Contents to Clipboard

pbcopy < ~/Documents/copy.txt

  • Paste from Clipboard

pbpaste

  • Save Clipboard Contents to a File

pbpaste > ~/Desktop/clipboard-content.txt

  • Execute Clipboard Contents

pbpaste | bash

  • Sort and Remove Duplicate Clipboard Lines

pbpaste | sort -u | pbcopy


Master these commands to streamline your macOS experience and unlock the full potential of the terminal.

Follow TexArxs for more tips on maximizing productivity! 🚀

Follow TexArxs on LinkedIn
Need Apple IT support for your team?
TexArxs handles MDM deployment, Mac support, and Apple IT management for startups and SMEs across India.
Talk to us →

We use cookies to improve your experience and analyse site usage. By continuing, you agree to our use of cookies. Read our Privacy Policy.