Skip to content

Terminal

The macOS’ version of the cp Unix command won’t create links

I ran into this while working on a Keyboard Maestro macro that creates hard links: The macOS version of cp won't create links, at least not in Sonoma. In Ventura, it works even though it throws the same error as it does in Sonoma.

Copying as hard links is part of the cp feature set, fully covered in its man pages. But it doesn't work in macOS. To confirm, try this:

When I ran into this, I searched and discovered that someone else had run into the same issue,1Apple Developer login required but that's the only mention I could find.

I have filed this bug as FB13255408 with Apple, and I'm hopeful they fix it soon. There is a workaround, obviously: Use ln instead. This works fine for individual hard links, but using cp to quickly copy an entire folder as hard links is a nicer implementation.



More helpful help for Terminal commands

I use Terminal a fair bit, for any number of things. But I don't use it all the time, and that means I sometimes struggle to remember syntax of commands. "Was it rsync source destination or the other way around? Or was it ln that was backwards of what I thought it should be?"

You can open the man page for a command, of course, but sometimes there's so much there that finding the simple thing you want is tough. Enter tldr, installable via Homebrew or MacPorts. tldr skips most of the detail of the man pages, providing user-curated examples of how to use a given command.

As an example, here's the aforementioned rysnc command's man page:

[continue reading…]



Convert epoch time to human-readable time in Terminal

This is a stupid-simple Unix tip, posting more as a reminder to myself than anything truly insightful—I keep forgetting these details, so by doing the work to create a post about it, I'll never forget them again…

I've been using unix time from the unix side of macOS quite a bit lately, as it's an easy way to get timestamps for things. Getting the epoch time is easy:

$ date +%s
1641735529

The thing I always forget is how to convert an epoch time back into a human-readable format of my choosing, despite it being shown in the man page. It's simple; use the -r option, like this:

$ date -r 1641735529
Sun Jan  9 05:38:49 PST 2022

And, of course, you can format it how you like using a strftime formatted format string, i.e.

$ date -r 1641735529 "+Today is %A, %B %e, and it's %I:%M:%S %p"
Today is Sunday, January  9, and it's 05:38:49 AM

Related: Yes, I wake up early; it started with macosxhints.com and needing to update the site before I left for my real job each day, and it persists 20 odd years later.



Simplify VPN connections via TunnelBlick

I use a VPN on our home router, which runs pfSense. When I'm on my laptop, I connect to the VPN for two reasons. The first is security when using unknown wifi connections. The second is for ease of access to my home Macs and network—when on the VPN, my laptop appears as part of the local network, so screen and file sharing are simple and 100% reliable.

To access the VPN, I use TunnelBlick, which runs as a menu bar application. Launch the app, activate its menu bar item, choose your VPN connection profile from the list, enter your password, and you're connected. But doing this several times a day gets annoying quite quickly. Thankfully, TunnelBlick includes AppleScript support.

Using that support and Keyboard Maestro, I wrote a few macros to simplify connecting to and disconnecting from our VPN, as well as changing the DNS address depending on whether I'm connected to the VPN or not.

Technically, the DNS address shouldn't have to be switched—I have the VPN and Tunnelblick configured to automatically switch on connect, but for whatever reason, it's just not happening. So I included DNS address switching in my macros.
[continue reading…]



Archiving and version control for Keyboard Maestro

As much as I rely on our own Many Tricks' apps every day, there's one I rely on more: Keyboard Maestro (KM), the macro app for macOS that can do pretty much anything. How much do I rely on it? The shrunken image at right lists all of my macro groups—not macros, just the groups holding the macros. In terms of actual macros, there are over 425 at present. (These are not all user-facing; many are macros that support other macros.)

I use KM for everything from gathering monthly utility bills to inserting HTML code in blog posts to generating replacement license files for users to controlling iTunes to decrufting URLs when copying (future post coming on that one) to automatically naming and filing documents I scan to storing snippets for insertion into our apps' help files to opening oft-used URLs to adding key functionality to many apps such as Excel, Mail, Messages, Photos, Preview, Safari, etc. In short, it's the single most-used app on any of my Macs.

For as much as I love KM, it has one major shortcoming: All of those macros live in one large XML file. Yes, I back it up to many local and cloud locations, so I'm not worried about losing it. It does mean, though, that if I mangle a single macro while trying to fix something, there's no easy way to get back to the working version (assuming I've gone past the point of multiple undo steps).

But now I can recover from such stupidity, thanks to the amazing Macro Repository Suite from Dan Thomas. This suite consists of two macros: One that updates (and initially creates) the repository, and one that restores a given macro from the repository.

[continue reading…]



See dot files at top of ls output in Linux

In Terminal on macOS, the ls (list directory contents) command sorts the output of its "all files" listing so that hidden files (those that begin with a dot) appear at the top of the list, like this:

$ ls -Alh
total 47640
-rw-r--r--@   1 robg  staff    28K Oct 26 15:00 .DS_Store
drwxrwxrwx@   5 robg  staff   160B Oct 23  2016 .TemporaryItems
... [trimmed for display]
drwxr-xr-x    8 robg  staff   256B Sep 19 08:31 .wine
drwx------   13 robg  staff   416B Apr 13  2019 Applications
drwx------+  20 robg  staff   640B Oct 26 12:36 Desktop
... [trimmed for display]

On the server that hosts my personal sites (as well as Many Tricks), however, ls doesn't sort the invisible files to the top:
[continue reading…]



Another way to open stock charts from mop in Terminal

On Sunday, I posted about my geeky solution to my non-functional Stocks Dashboard widget in Mojave. Then earlier today, I crafted a way to view one of the tracked stock's charts with a mouse click.

A commenter asked if there were any way to view the charts using a built-in tool, as purchasing Keyboard Maestro for just this one task is expensive (and a waste of Keyboard Maestro's capabilities). And in reality, when I first started working on my solution, I started in Automator…but quickly grew frustrated by its inability to do even basic text manipulation.

But then today, I remembered I can use AppleScript in Automator to work with the text, and the solution came together quickly after that: A new Service that appears when you right-click on text in a Terminal window:

[continue reading…]



View charts for stocks in the mop Terminal app

Yesterday, I noticed that the Stocks Dashboard widget in Mojave was no longer working. I couldn't find a similar (small window, always there, only stock prices) app that did what I wanted, but I did discover mop, a Go program that runs in Terminal. Using mop and Terminal's ability to save a window layout, I was able to craft a solution that worked for me.

Then commenter smayer97 asked…

Any solution to replace the mini-graphs at the bottom of the old Dashboard widget?

I didn't pay much attention to the graphs in the widget, so I hadn't considered them in my solution. And there's no way I was going to find a tidy graphing solution that also worked in Terminal. What I came up with isn't quite as convenient as having the graphs available at all times, but it's pretty close—I just have to click on a ticker symbol while holding down some modifier keys:

As you might have guessed, this is powered by a Keyboard Maestro macro, and I love how well it works.

[continue reading…]



Go old school Terminal for stock quotes

My main machine is still running Mojave, and will be for some time—our accounting app and my scanner both rely on 32-bit code. For a very long time, I've been using the built-in Stocks widget from the Dashboard (something else that's gone in 10.15) to track stocks I own or am interested in following.

I have two displays, so I just dedicate a small corner on one of them for the Dashboard widget, which I detach from the Dashboard using an old but still functional Dashboard devmode hint. The Stocks Dashboard widget is quite narrow, and not all that tall, so it didn't take a lot of space.

But recently, it broke, as you can see in the image at right. I set out looking for a replacement—just a simple desktop app that would open a window with stock quotes. Apple's own Stocks app doesn't meet my needs—it has a huge News area you can't close. Similarly, the Stocks section of the Today area in Notification Center requires mouse movement and action on my part to see.

I took a look at any number of third-party apps, but all of them were either full-blown stock traders/managers, lived in the menu bar or Dock, or were discontinued. I finally found what I was looking for, not in a desktop application, but in mop—an open source Go program—running in Terminal.

After a bit of setup work, here's what I'm now seeing1While I wish I had bought a lot of these years ago, I didn't—these are just some sample stocks on my desktop:

Yes, the window is slightly wider than my old one2It's actually incredibly wide, but I don't need to see the other columns, but it's not as tall, and I was able to find a spot for it. If you'd like to try mop yourself, setup is relatively simple.

[continue reading…]



How to upgrade a web host’s command-line PHP

The following is a very geeky, very niche1Where 'niche' is defined as 'of interest to maybe one person' tip, and I'm only documenting it here because it took me a while to figure it out, and I'd like to not have to go through that again if the need arises.

This site, and a few other personal projects, are hosted at Ionos, with whom I've been generally happy. On the web/GUI side, Ionos makes it really easy to control which version of PHP is used on your sites.

But I also have command line access to my server there, and I ran into an issue trying to run a PHP script (to upgrade another site). It threw an error, so I thought I'd check which version of PHP was in use…

$ which php
/usr/bin/php
$ /usr/bin/php --version
PHP 4.4.9 (cgi-fcgi) (built: Aug 29 2019 12:59:15)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

PHP 4.4.9 was discontinued in 2008—no wonder the script threw an error!

[continue reading…]