Category: macOS

How to enter ASCII control characters with your keyboard

close photo of a macbook pro keyboard

How to enter ASCII control characters?

Entering ASCII control characters depends on the specific keyboard layout and operating system you are using. Here’s a general guide for Linux, Windows, and macOS:

Linux

In most Linux terminals, you can enter ASCII control characters using the keys Ctrl + Shift + u in combination with a letter or symbol. For example:

  • Ctrl + Shift + u and then 0 + 1: ASCII code 0x01 (Start of Heading)
  • Ctrl + Shift + u and then 0 + 2: ASCII code 0x02 (Start of Text)
  • Ctrl + Shift + u and then 0 + 3: ASCII code 0x03 (End of Text)
  • And so on…

Windows

In the Windows operating system, you can use the following steps:

  1. For characters with ASCII values 0 to 31, you can typically enter them using the Alt key and the numeric keypad. For example, to enter ASCII 0x01, press Alt + 0 + 0 + 1.
  2. For some characters, you can use the Windows Character Map utility. Press the Win key + R to open the Run dialog, type charmap, and press Enter. Select the desired character and copy/paste it.

macOS

On macOS, you can use the following steps:

  1. Character Viewer: Press Control + Command + Space to open the Character Viewer. Search for the desired control character and insert it into your document.

Note that you may have to go to the dots menu at top left and select Customize to add the Unicode category. The Unicode category is under Code Tables.

Note: The availability of these methods may vary depending on your keyboard layout and the specific software you are using. If you’re using a specific text editor or terminal, it might have its own way of entering control characters.

What are ASCII control characters?

ASCII control characters are special characters in the ASCII (American Standard Code for Information Interchange) character encoding scheme that are used to control peripheral devices such as printers and teletypewriters. They are non-printable characters and typically have specific functions rather than representing printable symbols like letters or numbers.

Here is a list of some commonly used ASCII control characters along with their decimal and hexadecimal values:

Control CharacterASCII DezimalASCII HEXDescription
NUL000null character
SOH101start of header
STX202start of text
ETX303end of text
EOT404end of transmission
ENQ505enquiry
ACK606acknowledge
BEL707bell (ring)
BS808backspace
HT909horizontal tab
LF100Aline feed
VT110Bvertical tab
FF120Cform feed
CR130Dcarriage return
SO140Eshift out
SI150Fshift in
DLE1610data link escape
DC11711device control 1
DC21812device control 2
DC31913device control 3
DC42014device control 4
NAK2115negative acknowledge
SYN2216synchronize
ETB2317end transmission block
CAN2418cancel
EM2519end of medium
SUB261Asubstitute
ESC271Bescape
FS281Cfile separator
GS291Dgroup separator
RS301Erecord separator
US311Funit separator
   
DEL1277Fdelete (rubout)

Foto von Jess Bailey auf Unsplash

 

macOS: how to print a test page

colorful photo of macbook pro with dark background


To print a test page on a Mac, follow these steps:

  1. Open “System Preferences”.
  2. Click on “Printers & Scanners” (or “Print & Scan” depending on your macOS version).
  3. Select the printer you want to print a test page from.
  4. Click the “Open Print Queue”.
  5. A new window will open, showing the print queue for the selected printer.
  6. Look for the “Printer” menu at the top of the window and select “Print Test Page” or “Print Test Sheet.”
  7. Your printer will now print a test page.

Please note that the specific steps may vary slightly depending on your macOS version.

Foto von Andras Vas auf Unsplash

 

How to use your Mac for time-lapse like webcam shots

long exposure photo of a street in a city a night

When searching for a script that captures images from my Macs internal camera, I found a small tool called ImageSnap. This small tool is very simple in its usage, but it’s one of the key tools when you want to use your Mac as a webcam.

ImageSnap is a Public Domain command-line tool that lets you capture still images from an iSight or other video source.

Installation

ImageSnap can be conveniently installed through package managers like Homebrew and MacPorts. One of the simplest methods to install ImageSnap is by executing the following command:

brew install imagesnap

Usage

To use ImageSnap, open the macOS terminal and navigate to the folder where all your images should be stored. In my case, I used a folder located in iCloud Drive so that I can access those files from any other device that uses the same iCloud account.

Then I just provided the time interval between the images by using the -t parameter:

imagesnap -t 60

A value of 60 will result in a picture every minute (= 60 seconds).

There are several other options for ImageSnap to fine tune your image capturing. The help output gives you all the details:

imagesnap -h
USAGE: imagesnap [options] [filename-or-dir]
Version: 0.2.16
Captures an image from a video device and saves it in a file.
If no device is specified, the system default will be used.
If no filename is specfied, snapshot.jpg will be used.
If timelapse is used, the filename argument can be a directory where files will be saved.
JPEG is the only supported output type.
  -h          This help message
  -v          Verbose mode
  -l          List available video devices
  -t x.xx     Take a picture every x.xx seconds
  -n num      Limit to <num> snapshots in -t timelapse mode
  -q          Quiet mode. Do not output any text
  -w x.xx     Warmup. Delay snapshot x.xx seconds after turning on camera (default 3sec)
  -d device   Use named video device

Foto von Adrian Schwarz auf Unsplash.

Ping server on a specific port

Terminal

You can’t ping ports, as Ping is using ICMP which doesn’t have the concept of ports. Ports belong to the transport layer protocols like TCP and UDP. However, you could use nmap to see whether ports are open or not:

nmap -p 80 example.com

The output will look like this:

nmap -p 80 google.de
Starting Nmap 7.92 ( https://nmap.org ) at 2021-12-08 10:59 CET
Nmap scan report for google.de (142.250.185.131)
Host is up (0.017s latency).
rDNS record for 142.250.185.131: fra16s50-in-f3.1e100.net

PORT   STATE SERVICE
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds

Source: https://serverfault.com/questions/309357/ping-a-specific-port

brew: install Java on macOS

The following steps will guide you through the installation of Java on macOS.

First, check the available Java related formulas:

% brew search java

==> Formulae
app-engine-java              java                         javacc                       jslint4java                  pdftk-java
google-java-format           java11                       javarepl                     libreadline-java

Currently, there are two different version of Java: java and java11. To check the version of both, you can use the following commands:

% brew info java

openjdk: stable 16.0.1 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk.rb
License: GPL-2.0-only with Classpath-exception-2.0
% brew info java11

openjdk@11: stable 11.0.10 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk@11.rb
License: GPL-2.0-only

Depending on your requirements, you can install one of the above. For me, some of the libraries I use in Dart are currently not compatible with the latest Java version (16.0.1), so I decided to install Java 11 with LTS (long term support).

% brew install java11

This will install Java version 11.0.10 as listed in the output above. The output also shows the following hints:

For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk

openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have openjdk@11 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk@11 you may need to set:
  export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"

For me it was necessary to called the specified command, so that the system finds the java binary:

sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk

To see if Java was installed correctly, you can check the version of Java:

 % java --version

openjdk 11.0.10 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9)
OpenJDK 64-Bit Server VM (build 11.0.10+9, mixed mode)

That’s it!

Photo by Adam Wilson on Unsplash

Quick Look plugins for software development

Quick Look already supports multiple file types. But there ist more – especially for software development. Here are some plugins that make Quick Look even better.

Note: some of the plugins might not work instantly after brew install ... when you are on macOS Catalina or later. In this case, it is possible to download the plugin manually and copy the .qlgenerator file to ~/Library/QuickLook. This requires to run qlmanage -r (or a system restart) to enable the plugin.

QLMarkdown

QLMarkdown provides QuickLook support for markdown files (*.md). This plugin renders the markdown content and shows the result. To install QLMarkdown, use:

brew cask install qlmarkdown

For manual installation, the plugin is available at https://github.com/toland/qlmarkdown.

QLStephen

This Quick Look plugin provides a file preview for files without extension, e.g. README, INSTALL, Capfile, CHANGELOG, etc. It can be installed using Homebrew:

brew cask install qlstephen

For manual installation, the plugin is available at https://github.com/whomwah/qlstephen.

QLColorCode

This is a Quick Look plug-in that renders source code with syntax highlighting. To install the plugin, use Homebrew:

brew cask install qlcolorcode

For manual installation, the plugin is available at https://github.com/anthonygelibert/QLColorCode. If you want to configure QLColorCode, there are several defaults commands that are described on the download page.

Quick Look Json

This is a Quick Look plug-in that renders json files. To install the plugin, use Homebrew:

brew cask install quicklook-json

For manual installation, the plugin is available at http://www.sagtau.com/quicklookjson.html.

WebP QuickLook

This is an open-source QuickLook plugin to generate thumbnails and previews for WebP images. To install the plugin, use Homebrew:

brew install webpquicklook

For manual installation, the plugin is available at https://github.com/dchest/webp-quicklook.

Something is missing? Please let me know in the comments, if there are any other plugins that might be helpful for software development.

Photo by Shane Aldendorff on Unsplash

Create certificate for localhost domains on macOS

Step 1: create a self-signed root certificate

First, let’s create a self-signed root certificate:

openssl req -x509 -nodes -new -sha256 -days 390 -newkey rsa:2048 -keyout "RootCA.key" -out "RootCA.pem" -subj "/C=de/CN=localhost.local"
openssl x509 -outform pem -in "RootCA.pem" -out "RootCA.crt"

The parameter -days 390 sets the number of days, this certificate is valid. Starting on September 1st (2020), SSL/TLS certificates cannot be issued for longer than 13 months (397 days), see https://stackoverflow.com/a/65239775.

If this time is too long, you will receive an NET::ERR_CERT_VALIDITY_TOO_LONG error. In the command above, this value was set to 390 days, which works for me.

Step 2: define domains and subdomains that should be included in the certificate

For this, just create a text file named vhosts_domains.ext and insert the following contents:

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = *.mixable.blog.local
DNS.3 = mixable.blog.local

This example includes subdomains for a local development environment for the domain mixable.blog.local and all subdomains like www.mixable.blog.local or apps.mixable.blog.local.

If you plan to use a more general certificate e.g. to include all subdomains under *.*.blog.local, this will not work. The definition only supports ‘first level’ subdomains. It would be great, because this saves a lot of additional setup, but unfortunately this is note supported.

Step 3: create the certificate

Now let’s create the certificate:

openssl req -new -nodes -newkey rsa:2048 -keyout localhost.key -out localhost.csr -subj "/C=de/ST=State/L=City/O=Organization/CN=localhost.local"
openssl x509 -req -sha256 -days 1024 -in localhost.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile vhosts_domains.ext -out localhost.crt

Calling the two commands above will create the localhost certificate that includes all the provided domains and subdomains. Your file listing should look like this:

Step 4: make the certificate available for Apache

Depending on your system, copy all those files into the the configuration folder of the Apache installation. In my case, the installation was done with the help of brew, so the local path is:

<code>/usr/local/etc/httpd/cert/</code>

At the end, it’s not important where those files are located, because we no add this path to the vhost definitions. For this, open your vhosts file and link the crt and the key file as follows:

# mixable.blog.local
<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    DocumentRoot "/Users/mathias/Sites/mixable.blog.local"
    ServerName mixable.blog.local
    ServerAlias mixable.blog.local
    ErrorLog "/usr/local/var/log/httpd/localhost-error.log"
    CustomLog "/usr/local/var/log/httpd/localhost-access.log" common
</VirtualHost>
<VirtualHost *:443>
    DocumentRoot "/Users/mathias/Sites/mixable.blog.local"
    ServerName mixable.blog.local
    SSLEngine on
    SSLCertificateFile "/usr/local/etc/httpd/cert/localhost.crt"
    SSLCertificateKeyFile "/usr/local/etc/httpd/cert/localhost.key"
</VirtualHost>

If you have additional vhost definitions, you can add the <VirtualHost *:443> part to every server name entry and use the correct paths to SSLCertificateFile and SSLCertificateKeyFile.

After changing the vhost settings, it is required to restart your Apache server!

Step 5: add the certificates to macOS

When opening a local website, the certificate should be used but you might see a NET::ERR_CERT_INVALID error. This is the case, because modern browsers/systems do not trust self-signed certificates by default. to overcome this issue, we have to add the created certificates to the macOS Keychain Access. For this, open the *.crt files in Keychain Access:

So that they are know by macOS:

And finally, update the trust settings of each certificate to “Always trust”:

You should now be able to use a secure connection between your browser and your local server:

Step 6: additional fixes

The steps above might already work for Chrome and Safari. If you have problems with Firefox, just open settings and go to Privacy & Security. Then you have to import the root certificate file RootCA.crt, so that Firefox knows about your certificate.

Android Studio: when shortcuts do not work on macOS

Compared to other IntelliJ® based software, some shortcuts in Android Studio did not work for me. For example cmd + shift + F, which should open the global search did not work.

The reason for this is the keymap setting that was set to IntelliJ IDEA Classic. Setting the keymap to macOS (as shown in the figure below) solved the issue.

Android Studio Keymap settings