Created
September 29, 2022 02:08
-
-
Save porteusconf/714c602203deac6decb242a14f3e207a to your computer and use it in GitHub Desktop.
zsh shell script to detect if running under rosetta on apple-silicon m1 macs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Based on https://indiespark.top/software/detecting-apple-silicon-shell-script/ | |
arch_name="$(uname -m | cut -c 1-3)" # x86 or arm (to match arm64 or arm64e) | |
echo -n ${arch_name} "= specifically " | |
uname -m | |
if [ "${arch_name}" = "x86" ]; then | |
if [ "$(sysctl -in sysctl.proc_translated)" = "1" ]; then | |
echo "Running on Rosetta 2" | |
else | |
echo "Running on native Intel" | |
fi | |
elif [ "${arch_name}" = "arm" ]; then | |
echo "Running on ARM" | |
else | |
echo "Unknown architecture:" | |
uname -m | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using curl to download will avoid quarantine and warnings about untrusted software, unknown author, etc...
Note: Original script at https://indiespark.top/software/detecting-apple-silicon-shell-script/ would not work if
uname -m
were in future to returnarm64e
instead ofarm64
So as quick and dirty hack, changed it to look at only first 3 characters returned by
uname -m | cut -c 1-3
which would be justx86
orarm
and I think it should still work as intended.