Macos

Sound Selector MacOS

Sound Selector for MacOS

on MacOS, you can switch the input and output source on “system setting/sound”. i’d like todo this on the cli.

SwitchAudio

there is a litte tool called switchaudio. it can list, and also set the input/output device. let’s build a small wrapper around.

brew install switchaudio-osx

Usage

List Sound Devices

stoege@mac ~ % sound.sh

1: Externe Kopfhörer
2: Externes Mikrofon
3: Jabra Link 400
4: Mac mini-Lautsprecher
5: SRS-XB33
6: USB Audio Device

Set Sound Device

macos - hdiutil

Intro

hdiutil is a command-line utility on macOS that allows users to create, manipulate, and convert disk images. Disk images are virtual disk files that can contain the entire file system structure, including files, folders, and metadata. hdiutil provides a variety of functions related to disk images, and it’s a powerful tool for managing disk-related tasks on a Mac.

Basic Usage

create

echo -n "geheim" |hdiutil create -encryption -stdinpass -size 10m -volname encdata test.dmg -fs HFS+J

mount ro

echo -n "geheim" |hdiutil mount -stdinpass -readonly test.dmg

mount rw

echo -n "geheim" |hdiutil mount -stdinpass test.dmg

create, strong, mount

echo -n "geheim" |hdiutil create -encryption AES-256 -stdinpass -attach -volname encdata -size 10m test.dmg -fs HFS+J

unmount

hdiutil unmount /Volumes/encdata

or

Monaspace

Monaspace

Do you like it ? I do …

Install macOS

brew tap homebrew/cask-fonts
brew install font-monaspace

Any Comments ?

sha256: 9f088f3023c2e5c26817ccddbfb49ea25dd6f08d0ba3ac6e7ca9038f0d2e2547

MacOS - Kernel Extensions

see: https://nektony.com/how-to/remove-kext-on-mac

System Extensions

> ll /System/Library/Extensions/ |head
total 0
drwxr-xr-x@ 3 root  wheel   96 May 13 00:29 AFKACIPCKext.kext
drwxr-xr-x@ 3 root  wheel   96 May 13 00:29 AFTK_Kext.kext
drwxr-xr-x@ 3 root  wheel   96 May 13 00:29 AGXFirmwareKextG13GRTBuddy.kext
drwxr-xr-x@ 3 root  wheel   96 May 13 00:29 AGXFirmwareKextG13XRTBuddy.kext
drwxr-xr-x@ 3 root  wheel   96 May 13 00:29 AGXFirmwareKextG14GRTBuddy.kext
drwxr-xr-x@ 3 root  wheel   96 May 13 00:29 AGXFirmwareKextG14PRTBuddy.kext
drwxr-xr-x@ 3 root  wheel   96 May 13 00:29 AGXFirmwareKextG14XRTBuddy.kext
drwxr-xr-x@ 3 root  wheel   96 May 13 00:29 AGXFirmwareKextRTBuddy64.kext
drwxr-xr-x@ 3 root  wheel   96 May 13 00:29 AGXG13G.kext

System Extensions

/Library/Apple/System/Library/Extensions> ll
total 0
drwxr-xr-x  3 root  wheel  96 May 13 00:29 AppleKextExcludeList.kext
drwxr-xr-x  3 root  wheel  96 May 13 00:29 AppleMobileDevice.kext

Own Extensions

stoege@play224:~> ll /Library/Extensions/ |head
total 0
drwxr-xr-x@  3 root  wheel    96 May 27 14:11 CH34xVCPDriver.kext
drwxr-xr-x@  3 root  wheel    96 May 27 14:17 Dropbox.kext
drwxr-xr-x   3 root  wheel    96 May 13 00:29 HighPointIOP.kext
drwxr-xr-x   3 root  wheel    96 May 13 00:29 HighPointRR.kext
drwxr-xr-x@  3 root  wheel    96 May 27 14:11 HoRNDIS.kext
drwxr-xr-x@  3 root  wheel    96 May 27 14:18 SiLabsUSBDriver.kext
drwxr-xr-x@  3 root  wheel    96 May 27 14:11 SoftRAID.kext
drwxr-xr-x@ 15 root  wheel   480 May 27 14:10 Unsupported
drwxr-xr-x@ 33 root  wheel  1056 May 27 14:26 backup

Any Comments ?

sha256: 8a9836f3b6b24efeab82363400d893d801e1576f4527a684805be9de0b609617

Dotnet - Hello World

Running a WebApp in 5min ?

ASP.NET Tutorial - Hello World in 5 minutes

in a Language you never touched before … ? a Microsoft App running on Linux running in Docker running on macOS … ?

Let’ give a try …

Fireup Ubuntu via Docker, do Port Forward

docker run -it -p 5123:5123 --name dotnet-hello ubuntu:latest

add basics

apt-get update && apt-get -y upgrade && apt-get -y install wget

add dotnet

wget https://packages.microsoft.com/config/ubuntu/22.10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb && rm packages-microsoft-prod.deb
apt-get update && apt-get install -y dotnet-sdk-7.0
dotnet --version

build webapp

dotnet new webapp -o MyWebApp --no-https -f net7.0

run webapp, change IP & Port

cd MyWebApp
sed -i 's#"applicationUrl".*#"applicationUrl": "http://0.0.0.0:5123",#' Properties/launchSettings.json
dotnet watch

Hello World

Url Shortener for CLI

CLI Url Shortener

wrote a little URL Shortener in Python with FastAPI and a wrapper script for cli usage. needs httpie & jq packages. python backend is under development, cli wrapper for different os right here …

Usage

somehost$ ./myurlshort

usage: /usr/local/bin/myurlshort http://veeeeeeeeeeeeeeeeeeeeeeeeeery.long.url.to

anyhost$ ./myurlshort http://my-url-to-short.egal.world.planet.universe
https://url.stoege.net/xXxXx

CLI Wrappers

OpenBSD

cat << 'EOF' > myurlshort
#!/usr/bin/env bash

# url shortener for openbsd, v1.0, 2022-09-12, by @stoege

which jq >/dev/null || ( echo -e "*** jq not installed ***\ndoas pkg_add jq\n"; )
which https >/dev/null || ( echo -e "*** httpie not installed ***\ndoas pkg_add httpie\n"; )

if [[ $# -ne 1 ]]; then
  echo -e "\nusage: $0 http://veeeeeeeeeeeeeeeeeeeeeeeeeery.long.url.to\n"
  exit 1
fi

url="$1"

# check if http/https set
if ! ( [[ $1 == http* ]] || [[ $1 == https* ]] ); then
  url="https://$1"
  echo "adding https:// ... -> $url"
fi

https post url.stoege.net/url target_url="$url" |jq -r '.url'

exit 0
EOF

chmod 755 myurlshort

macOS

cat << 'EOF' > myurlshort
#!/usr/bin/env bash

# url shortener for macos, v1.0, 2022-09-12, by @stoege

which jq >/dev/null || ( echo -e "*** jq not installed ***\nbrew install jq\n"; )
which https >/dev/null || ( echo -e "*** httpie not installed ***\nbrew install httpie\n"; )

if [[ $# -ne 1 ]]; then
  echo -e "\nusage: $0 http://veeeeeeeeeeeeeeeeeeeeeeeeeery.long.url.to\n"
  exit 1
fi

url="$1"

# check if http/https set
if ! ( [[ $1 == http* ]] || [[ $1 == https* ]] ); then
  url="https://$1"
  echo "adding https:// ... -> $url"
fi

https post url.stoege.net/url target_url="$url" |jq -r '.url'

exit 0
EOF

chmod 755 myurlshort

Alpine

cat << 'EOF' > myurlshort
#!/usr/bin/env bash

# url shortener for alpine, v1.0, 2022-09-12, by @stoege

which jq >/dev/null || ( echo -e "*** jq not installed ***\napk add jq\n"; )
which https >/dev/null || ( echo -e "*** httpie not installed ***\napk add httpie\n"; )

if [[ $# -ne 1 ]]; then
  echo -e "\nusage: $0 http://veeeeeeeeeeeeeeeeeeeeeeeeeery.long.url.to\n"
  exit 1
fi

url="$1"

# check if http/https set
if ! ( [[ $1 == http* ]] || [[ $1 == https* ]] ); then
  url="https://$1"
  echo "adding https:// ... -> $url"
fi

https post url.stoege.net/url target_url="$url" |jq -r '.url'

exit 0
EOF

chmod 755 myurlshort

Any Comments ?

sha256: 75b0a781fd4569791f3d43932694e155a9443a739f0bf43b0e0904ce299eec3e

macOS

some adaption for macOS

CUPS

enable cups

cupsctl WebInterface=yes
  • http://localhost:631/printers/

Shell

macOS is using zsh since while. If you wanna switch back to bash, here some Notes …"

Switch to Bash

chsh -s /bin/bash

Switch to Zsh

chsh -s /bin/zsh

install brew

the famous package manager for macOS

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

install keychain

if you work with ssh agent, you may wanna try keychain …

brew install keychain

build .bash_profile

this will overwrite your existing .bash_profile

Doas

doas, an alternative to sudo

Everybody knows sudo … right ? but the openbsd guys hacked a small and secure replacement called doas …

simple, secure and clever

here a good and quick tutorial

An introduction on Vultr, the Source Code on Github and the Man Page

Installation OpenBSD

On OpenBSD, it’s already in the Base System and no need to install anything.

Installation Linux

On Linux, for Example, you have to add the Package