1134Folder Actions in macOS

Folder Actions are the hidden superpowert in macOS. They are triggered when files are added to a folder, they then can execute an action.

The Action can be written in Automator, AppleScript or Javascript.

They are great for repetitive actions.

Problem: I have a Google Sheet that I am exporting as CSV, which in turn is used to contruct a table within Hugo. Downloading the CSV from Sheets puts it on the Desktop.

This action checks the Desktop, if it finds the file, it moves it.

Writing the Action in Automator

Filter Finder Items makes sure only the desired files are affected.

Setting up Folder Action

  • Select your Folder
  • Right-click and say Services -> Folder Actions Setup...

Choose a Script to attach.

Now whenever a file matching the criteria is added to the folder, the Folder Action is executed.

1044networkQuality

Testing network speed on macOS:

networkQuality

Example output:

Downlink: capacity 24.052 Mbps, responsiveness 321 RPM - Uplink: capacity 0.000
Downlink: capacity 24.052 Mbps, responsiveness 294 RPM - Uplink: capacity 20.669
Downlink: capacity 24.548 Mbps, responsiveness 250 RPM - Uplink: capacity 20.669
Downlink: capacity 24.548 Mbps, responsiveness 248 RPM - Uplink: capacity 17.763
Downlink: capacity 26.099 Mbps, responsiveness 243 RPM - Uplink: capacity 17.763
Downlink: capacity 26.099 Mbps, responsiveness 243 RPM - Uplink: capacity 16.716
Downlink: capacity 26.567 Mbps, responsiveness 240 RPM - Uplink: capacity 16.716
Downlink: capacity 26.567 Mbps, responsiveness 240 RPM - Uplink: capacity 16.632
Downlink: capacity 27.436 Mbps, responsiveness 237 RPM - Uplink: capacity 16.632
Downlink: capacity 27.436 Mbps, responsiveness 235 RPM - Uplink: capacity 15.908
Downlink: capacity 27.120 Mbps, responsiveness 194 RPM - Uplink: capacity 15.908
Downlink: capacity 27.120 Mbps, responsiveness 185 RPM - Uplink: capacity 16.711
Downlink: capacity 25.164 Mbps, responsiveness 156 RPM - Uplink: capacity 16.711
Downlink: capacity 25.164 Mbps, responsiveness 150 RPM - Uplink: capacity 16.939
Downlink: capacity 24.892 Mbps, responsiveness 124 RPM - Uplink: capacity 16.939
Downlink: capacity 24.892 Mbps, responsiveness 118 RPM - Uplink: capacity 17.627
Downlink: capacity 23.011 Mbps, responsiveness 108 RPM - Uplink: capacity 17.627
Downlink: capacity 23.011 Mbps, responsiveness 100 RPM - Uplink: capacity 15.339
Downlink: capacity 22.093 Mbps, responsiveness 87 RPM - Uplink: capacity 15.339
Downlink: capacity 22.093 Mbps, responsiveness 85 RPM - Uplink: capacity 13.592
Downlink: capacity 23.291 Mbps, responsiveness 63 RPM - Uplink: capacity 13.592
Downlink: capacity 23.291 Mbps, responsiveness 63 RPM - Uplink: capacity 14.177
Downlink: capacity 23.291 Mbps, responsiveness 43 RPM - Uplink: capacity 17.627 
==== SUMMARY ====
Uplink capacity: 17.627 Mbps
Downlink capacity: 23.291 Mbps
Responsiveness: Low (43 RPM)
Idle Latency: 19.708 milliseconds

982Mysterious SSH Connection Problem

Step before: Trying to connect to a server with a SSH key. System: OSX, Big Sur

Connecting to a Server via SSH fails:

georg@Fischer ~ % ssh trembl@myserver -v           
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/georg/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to myserver.com port 22.
ssh: connect to host myserver.com port 22: Operation timed out

Did not work for ca. 1 hour. Same connection problem to different account with same provider, other account with same provider worked.

(Possible) Solution: Intentionally mis-spelled username, -v not stopping and timing out, log-in now possible.

Update 1

Use

nmap -Pn -p22 myserver

to check if the port is open or filtered.

Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-03-30 14:15 JST
Nmap scan report for trembl@myserver (xx.xx.xxx.xxx)
Host is up (0.21s latency).
rDNS record for xx.xx.xxx.xxx: xx.xx.xxx.xxx

PORT   STATE     SERVICE
22/tcp filtered  ssh

It should say:

PORT   STATE SERVICE
22/tcp open  ssh

Update 2

Creating a ssh connection to the server from another computer (on the same network) worked. Somehow, after that check, the connection on this computer also worked. Very mysterious.

Update 3

Approach 2 did not work the next time. Switching to a different network (phone hotspot) worked. Maybe restarting the router?

981sed, -i and the macOS

Doing a Search and Replace on the shell should not be difficult:

find . -name "*.html" -exec sed -i "s/searchPattern/replacePattern/g" {} +

However, on macOS this error message occurs:

sed: 1: "./aaa/a ...": invalid command code .
sed: 1: "./aaa/b ...": invalid command code .
sed: 1: "./aaa/c ...": invalid command code .
...

It turns out, on MacOS the -i parameter needs to be followed by an empty string:

find . -name "*.html" -exec sed -i "" "s/searchPattern/replacePattern/g" {} +