Home
Cool Beach Cool Mac OS

Cool Beach Cool Mac OS

May 12 2021

Cool Beach Cool Mac OS

— Paul Annesley, September 2012

One of the core components of Mac OS X is launchd, and it turns out it can do some cool things.

I particularly like the idea of using QueueDirectories to monitor and act upon files dropped into a directory, without having to run any extra daemons. The files could be uploaded to S3, transcoded to a different video format, gzipped… anything.

See the best Beach iPhone Backgrounds collection. If you see some Beach iPhone Backgrounds you’d like to use, just click on the image to download to your desktop or mobile devices. The command line (or Terminal for you Mac fans) is a throwback to a simpler age of computing, before mouse pointers and application windows and desktop wallpaper. Back when it was just you and a.

If you’re wondering if their are cool ways to personalise your macOS, then this is the right article to dig into. You can quickly change your Mac's look and feel. Learn how to customise your Mac—adjusting your macOS preferences to your personal tastes. There are even things that other open source operating systems can't even come close to the cool things the Mac can do. Now, if you had asked more specifically about cool shortcuts, fine, but you just asked about all the cool things a Mac can do. And thus, we have provided. Cool Mac OS X Leopard Tricks!: Ever wonder how to do certain things on a Mac that you can do on a PC, but since you switched over, couldn't do? Or have you ever wondered how to stop certain annoying things on your mac? In this instructable, I'm going to explain how to do some coo.

Anyway, I recently fell into the launchd documentation, and came out with this write-up. Let me know if you find it useful.

Overview

The first thing that the Mac OS kernel runs on boot is launchd, which bootstraps the rest of the system by loading and managing various daemons, agents, scripts and other processes. The launchd man page clarifies the difference between a daemon and an agent:

In the launchd lexicon, a “daemon” is, by definition, a system-wide service
of which there is one instance for all clients. An “agent” is a service that
runs on a per-user basis. Daemons should not attempt to display UI or
interact directly with a user’s login session. Any and all work that involves
interacting with a user should be done through agents.

Daemons and agents are declared and configured by creating .plist files in various locations of the system:

Perhaps best of all, launchd is open source under the Apache License 2.0. You can currently find the latest source code on the Apple Open Source site.

launchd as cron

The Mac OS crontab man page says:

Turns out launchd has a simple StartInterval <integer> property, which starts the job every N seconds. However the true cron-like power lies in StartCalendarInterval:

Lets find the shortest example of this in action:

Better than cron? Apart from better handling of skipped jobs after system wake, it also supports per-job environment variables, which can save writing wrapper scripts around your cron jobs:

So, anything XML is obviously worse than 0 52 3 * 5 /path/to/command, but launchd is packing more features than cron, so it can pull it off.

launchd as a filesystem watcher

Apart from having an awesome daemon/agent manager, Mac OS X also has an excellent Mail Transport Agent called postfix. There’s a good chance your ISP runs the same software to handle millions of emails every day. We’ll be using it as an example of how launchd can start jobs based on filesystem changes.

Because your laptop isn’t, and shouldn’t be, a mail server, you don’t want postfix running all the time. But when messages are injected into it, e.g. by a script shelling out to /usr/sbin/sendmail or /usr/bin/mail, you want them to be delivered straight away.

Here’s how Mac OS X does it (/System/Library/LaunchDaemons/org.postfix.master.plist):

We’ll start with the simple part. ProgramArguments passes -e 60 to postfix, described thusly:

So postfix is told to exit after running for 60 seconds. The mystery (to me, earlier today, at least) is how it gets started. It could be on a cron-like schedule, but (a) it isn’t, (b) that would suck, and © it would result in delayed mail delivery. It turns out the magic lies in QueueDirectory, which I initially overlooked thinking it was a postfix option. The launchd.plist man page says:

The Launchd Wikipedia page actually goes into more detail:

So launchd can monitor a directory for new files, and then trigger an agent/daemon to consume them. In this case, the postfix sendmail(1) man page tells us that “Postfix sendmail(1) relies on the postdrop(1) command to create a queue file in the maildrop directory”, and the man page for postdrop(1) tells us that /var/spool/postfix/maildrop is the maildrop queue. launchd sees new mail there, fires up postfix, and then stops it after 60 seconds. This might cause deferred mail to stay deferred for quite some time, but again; your laptop isn’t a mail server.

launchd as inetd

Tranditionally the inetd and later xinetd “super-server daemon” were used to listen on various ports (e.g. FTP, telnet, …) and launch daemons on-demand to handle in-bound connection, keeping them out of memory at other times. Sounds like something launchd could do…

Lets create a simple inetd-style server at ~/Library/LaunchAgents/my.greeter.plist:

Load it up and give it a shot:

launchd as god!

You can use launchd to ensure a process stays alive forever using <key>KeepAlive</key><true/>, or stays alive under the following conditions.

  • SuccessfulExit — the previous run exited successfully (or if false, unsuccessful exit).
  • NetworkState — network (other than localhost) is up (or if false, down).
  • PathState — list of file paths exists (or if false, do not exist).
  • OtherJobEnabled — the other named job is enabled (or if false, disabled).

These can be combined with various other properties, for example:

  • WorkingDirectory
  • EnvironmentVariables
  • Umask
  • ThrottleInterval
  • StartOnMount
  • StandardInPath
  • StandardOutPath
  • StandardErrorPath
  • SoftResourceLimits and HardResourceLimits
  • Nice

More?

There’s some more information at developer.apple.com, and the launchd and launchd.plist man pages are worth reading.

Let me know if you find any of this useful… I’m @pda on Twitter.

You can leave comments on Hacker News if that’s more your thing.

Terminal is not for mere mortals, you're probably thinking. It's a kind of sacred knowledge that only geeks and Mac geniuses possess. But if you get through your first command line, you'll find it's not that terrifying. In fact, using Terminal is like applying Harry Potter wizardry to your tasks. Once you know the right spells, you can break any laws of how applications behave and do some unbelievable things that even the most experienced Mac people can't. Isn't it seducing to try?

We've chosen just a few of Terminal's most impressive features. For a more serious take on Mac terminal commands, check out this article. Okay, are you ready to type in your first code? To start the journey, learn how to open the Terminal app on Mac: Click Launchpad and then type Terminal in the search bar.

1) Make your Mac talk to you

One of the simplest commands can be very fun, especially when you are planning a prank on somebody. Just type any text in Terminal, and your computer will speak it in your Mac's default voice. But there are about 20 voices and intonations to choose from, plus the ability to convert an entire text file into speech. So here's a slick audiobook maker at your hand.

Open up Terminal, type in:
say followed by a space and any text you want to hear

2) Customize Login Message

This is what makes Mac more personal and humanized. For example, you can write an inspirational motto or helpful information for other users if it's a public library computer. It might even be a way to retrieve your MacBook if you lose it — if you set a login message with your contact information. Once again, there's much room for pranking other people, but we won't go deep into that.

Open up Terminal, type in:

sudo write /Library/Preferences/com.apple.loginwindow LoginwindowText 'Custom Text Here'

3) Watch Star Wars in Terminal app

In Terminal symbols, of course. This could be the greatest trick which makes no particular sense, but even if just for the coolness alone, you should try it. The Death Star, R2D2, spaceships, and the rest of the Episode 4 story retold in Terminal graphics will blow your friends away at the party. And there is no sound, by the way.

Open up Terminal, type in:
telnet towel.blinkenlights.nl
On macOS Sierra and higher macOS versions, you should use a different command:

nc towel.blinkenlights.nl 23

4) Show hidden files in Finder

This isn't as funny as the previous one, but searching for important files is no joke. With this command, you'll be able to see everything on your Mac, even files that were omitted from standard display.

Open up Terminal, type in:

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

This should summon Finder with previously hidden files shown grayed out.
To reverse this operation (be aware that you may be swamped with lots of irrelevant system files), just substitute TRUE for FALSE in the command line above:

defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder

5) Pay a visit to a psychiatrist

Funny Mac terminal commands are many. This is a classic Easter egg type of joke macOS developers famous for. When you're feeling stressed, talking to a friendly chatbot will at least make you smile. Strangely enough, this therapy may be actually working because you are asked to verbalize your emotions by giving them a closer look. And the psychiatrists (the real ones) will confirm that sometimes it works.

Open up Terminal, type in:
emacs and then hit Return. Press Esc, then x, and finally type doctor

6) See iTunes songs notification via Terminal app

A clever addition if you normally work with the music in the background. If you fell in love with a particular track from your playlist, you don't need to open iTunes to find out the artist's name. It will pop up on your Mac Dock from now on. Though a bit strange, this feature isn't included by default because it's really a timesaver.

Open up Terminal, type in:

defaults write com.apple.dock itunes-notifications -bool TRUE

Close the dock using the following command:

killall Dock

7) Play simple games

Cool Beach Cool Mac Os Catalina

This is another retro cool feature to cheer you up once in a while. You can play Tetris, Pong, Snake, and a dozen of other arcade games. Once you have unlocked these nice hidden toys, you'll surely get to love your Mac more. Prepare to use your arrow keys.

Cool Beach Cool Mac Os X

Mac

Open up Terminal, type in:
emacs. Press Enter to open it up, press Esc then x. Now you have to type the name of the particular game, and that's it.
Game names:

  • tetris
  • pong
  • snake
  • solitaire
  • 5x5
  • landmark
  • doctor

What you learn from using Mac Terminal commands is that nothing is really impossible if you're on a Mac. But it's better to start your Terminal experience with these funny little tricks and then go to something serious. This program has a nearly infinite number of magic spells to choose from.

8) Make your Mac faster and more responsive

Okay, this has nothing to do with Terminal. But who wouldn’t want their MacBook as speedy and efficient as back then, on its first day? Surprisingly, this can be achieved easily, Terminal-style way — with the aid of CleanMyMac X.

  • Remove up to 74 GB of junk from your Mac
  • Uninstall unwanted apps completely
  • Speed up Mac with maintenance scripts
  • Fully clean browsers and messengers

Cool Beach Cool Mac Os Download

Download the app from the developer’s site for free
Hope you found this article helpful, stay tuned for more!

Cool Beach Cool Mac OS

Leave a Reply

Cancel reply