I was working on something with Peter about Moom and its disk usage (it doesn’t use much), and I was curious as to just how long Moom had been running on my Mac. I last rebooted my Mac a week ago, but I often quit and relaunch our own apps to run test versions.
Finder has this info, but that requires finding the running app in Finder. I wanted a quicker solution. In Activity Monitor (and ps in Terminal), you can see how much CPU time an activity has taken…
…but that doesn’t really help at all with knowing when the app (or process) launched. As long as you’re in Activity Monitor, you can get the information by doing the following:
- Click once on the app or process of interest.
- Press Command-I or click the small ‘i’ icon in the toolbar.
- In the new window that opens, click Sample, then wait.
When the sample is complete, you’ll see its output, and included there is the selected item’s launch date and time:
Analysis of sampling Moom (pid 89861) every 1 millisecond
Parent Process: ??? 
Date/Time: 2017-02-15 07:41:18.611 -0800
Launch Time: 2017-02-13 19:44:11.957 -0800
That’s all fine if you’re in Activity Monitor, but a bit of a pain if you need to launch it, find the app, run a sample, etc.
As you might expect, there’s another way via Terminal: The lsappinfo command, which queries CoreApplicationServices about any app or process on your Mac.
Over the weekend, I was testing how some of our apps work when the CPUs are busy. One way to load the CPUs is to rip a Blu-ray disc, but I was looking for a more controllable CPU load.
A quick search through the Mac OS X Hints archive (use this tip to search the site) found the answer from 15 years ago: Just say yes in Terminal to generate sizable CPU loads…
More specifically, use this command in Terminal:
yes > /dev/null &
If there’s an award for strangest Unix utility, yes might just be the winner. All it does is output y (or whatever you list after the y; the man page suggests an expletive) until you kill the task.
The above command sends the output (via the > redirect) to the null device, which discards it. The ampersand sends the job to the background, so you get your Terminal prompt back.
You can run this command multiple times, each loading the CPU even more heavily (the screenshot shows three yes tasks running). Keep an eye on Activity Monitor to see just how much CPU it takes—as shown above, it does a great job at loading the CPU.
You can kill the tasks by issuing the command killall yes in Terminal, or by quitting Terminal—you’ll be told that quitting will terminate the tasks.
Really long-time Unix users—as in mainframe-based Unix—are probably familiar with fortune. This silly little program grabs a random line from a collection of files holding quotes, sayings, jokes, etc. The Unix I used many decades ago would print an entry from fortune each time you started a new session. Here are some examples of what might greet me each time…
"It's a dog-eat-dog world out there, and I'm wearing Milkbone underware."
-- Norm, from _Cheers_
Mobius strippers never show you their back side.
All constants are variables.
Years ago, I had set up my Mac’s Terminal to output a fortune each time I opened a new session (window). At some point, though, I forgot to set it up on a new system, so it was gone. While fortune isn’t included in macOS’ Unix core by default, there are many ways to get it back, and it’s relatively simple to do so. Here’s one way…
I recently explained how I captured a series of screenshots and turned them into a movie. While I was working on my tweet about the write-up, I thought an animated GIF of the final movie would be a nice way to show what it was I was trying to do. So that’s what I wound up doing:
So how did I create the animated GIF from the movie file? I know there are any number of great apps that will do this (ScreenFlow, for one), but I had another thought: While working on the animated screenshot movie (which I created using ffmpeg), I had happened to read about ffmpeg’s ability to create high quality animated GIFs, so I thought I’d give that a try.
While working on my massive Blu-ray ripping comparison, I wanted more information about what some of the transcode-video presets were doing. That is, if you pick --target big, exactly what settings are being used to rip the video?
It turns out there’s --dry-run option for transcode-video that will tell you exactly that. (I’ve added some line breaks for readability here.)
$ transcode-video --dry-run --target big --mp4 Miss_Peregrine\'s_Home.mkv
--output=Miss_Peregrine\'s_Home.mp4 --markers --encoder=x264
--crop=0:0:0:0 --strict-anamorphic --rate=30 --pfr --encoder-preset=medium
--encoder-profile=high --encoder-level=4.0 --quality=1 --audio=1,1
What’s neat is that you can also use this to see what the default options are for transcode-video when you don’t supply it with any options. Just use the --dry-run parameter option but leave off any of the presets (i.e. --target big), and the output will show you the defaults.
In addition, you can use it on already-ripped media to get their details as well, regardless as to how you ripped the movie.
In a related vein, I was having issues with the above rip, because I thought that the surround sound track wasn’t being ripped. Again, thanks to Don, I learned about a second command line option for transcode-video that reveals exactly what’s in a ripped video.
As I’ve written about in the past, I use Don Melton’s video transcoding tools to rip Blu-Ray discs. I also use Homebrew to install some of the transcode video dependencies, as well as other Unix tools.
Keeping these tools current isn’t overly difficult; it only requires a few commands in Terminal:
$ brew update
$ brew upgrade
$ sudo gem update video_transcoding
My problem is that I often forget to do this, because—unlike most GUI Mac apps and the Mac App Store—there’s no built-in “hey, there’s an update!” system. Suddenly, two months and many revisions later, I finally remember (usually when I see a tweet about a new version of something.) So I thought I’d try to write my own simple update reminder.
I didn’t really want a scheduled task, like a launchd agent—it’s not like these tools need to stay current on a daily basis. (And one of them needs to run with admin privileges, which complicates things.) I just wanted something that would remind me if it’d been a while since I last checked for updates, and then install the updates if I wanted it to do so.
After mulling it over, I came up with a script that runs each time I open a Terminal window (which I do daily). The referenced script looks at the date on a check file, and asks me if I’d like to check for updates if that date is more than a week older than today’s date. This is perfect for my needs: The reminder is automatic, but I can choose when to install the updates based on what I’m doing at the time. If it’s been under a week since I last checked, nothing at all is different about my Terminal launch.
Read on for the script and implementation details. (Note: This is not written for a Terminal beginner, as it assumes some knowledge about how the shell works in macOS.)
Quite often, I find myself with a number of images (screenshots, typically) that I’ll want to convert from one format to another. If you search the Mac App Store, there are probably 300 apps that will let you do this; many are probably free. You could also use Automator, which has some good image conversion abilities, but can’t (for example) specify the quality of a JPEG conversion.
But the best way I’ve ever found is to use a tool that’s been included with every copy of macOS since the release of Mac OS X 10.3 (Panther) in October of 2003: A command line tool called sips. Yes, it requires using Terminal, but it’s quite easy to use. sips can modify one file, or any number of files, converting from one format to another. You can also use sips to resize images, rotate images, and more.
Basic usage of sips is straightforward. (The following is written for Terminal neophytes, so apologies for any over-explaining). Assume you have an image named Beach party.tiff that you’d like to convert into a smaller JPEG, but with a relatively high quality setting. Here’s how you’d do it using sips:
- Open Terminal, in Applications > Utilities.
- Type cd, then press the Space Bar, then drag in the folder that contains the image(s) to be converted. (Alternatively, you can use this tip to directly open the selected Finder folder in Terminal.)
- Type this, then press Return: sips -s format jpeg -s formatOptions 80 "Beach party.tiff" --out "Beach party.jpg"
When you press Return, sips will convert your image file—and it’s really fast, even on larger files. The formatOptions item lets you set the quality of the JPEG in either percentage (as I used), or you can use words: low, normal, high, or best. Hopefully obviously, you specify the new filename after the --out string.
Note that the filename is enclosed in quotes. Those quotes are required, otherwise any spaces in your filenames will cause the command to break.
The real power of sips isn’t in converting one file, though; it’s in batch converting many files. Here’s how to do that…