Skip to content

Instantly share code, notes, and snippets.

@porteusconf
Created September 29, 2022 02:08
Show Gist options
  • Save porteusconf/714c602203deac6decb242a14f3e207a to your computer and use it in GitHub Desktop.
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
#!/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
@porteusconf
Copy link
Author

porteusconf commented Sep 29, 2022

Using curl to download will avoid quarantine and warnings about untrusted software, unknown author, etc...

cd /Users/Shared
curl -LJO https://gist.githubusercontent.com/porteusconf/714c602203deac6decb242a14f3e207a/raw/5f9d9247715908d508ff5b8199e429f3573d7516/rosetta2detect.sh
chmod a+x rosetta2detect.sh
./rosetta2detect.sh

Note: Original script at https://indiespark.top/software/detecting-apple-silicon-shell-script/ would not work if uname -m were in future to return arm64e instead of arm64
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 just x86 or arm and I think it should still work as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment