Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Reproducing music on macOS can be an essential task for users who want to automate their media playback or integrate it into scripts. While macOS provides a robust graphical user interface for playing music through applications like iTunes (now Apple Music) and QuickTime, there are also command-line tools that can be used to play music directly from the Terminal. This article will guide you through the process of playing music using the Terminal on macOS, highlighting the importance of this capability for automation and scripting purposes.
Examples:
Using afplay
Command:
The afplay
command is a built-in utility in macOS that allows you to play audio files from the Terminal. It supports various audio formats, including MP3, AAC, and WAV.
Example:
afplay /path/to/your/audiofile.mp3
This command will play the specified audio file. You can also control the volume and playback speed using additional flags.
Volume Control:
afplay /path/to/your/audiofile.mp3 -v 0.5
Playback Speed:
afplay /path/to/your/audiofile.mp3 -r 1.5
Using osascript
to Control Apple Music:
osascript
is a command-line utility that allows you to execute AppleScript commands. You can use it to control the Apple Music application.
Example:
osascript -e 'tell application "Music" to play'
This command will start playing the current track in Apple Music. You can also use it to pause, skip, or play specific playlists.
Pause Playback:
osascript -e 'tell application "Music" to pause'
Play Specific Playlist:
osascript -e 'tell application "Music" to play playlist "Your Playlist Name"'
Using mpg123
for MP3 Files:
If you prefer using third-party tools, mpg123
is a command-line MP3 player that can be installed via Homebrew.
Installation:
brew install mpg123
Playing an MP3 File:
mpg123 /path/to/your/audiofile.mp3
These methods provide flexible options for playing music directly from the Terminal on macOS, making it easier to integrate audio playback into scripts and automate tasks.