Python run file

# 1. Navigate to the folder containing your bot files
cd ~/Documents/bots || exit

# 2. Convert .rtf to .py if it exists
if [ -f “telegram_to_email.py.rtf” ]; then
textutil -convert txt telegram_to_email.py.rtf
mv telegram_to_email.txt telegram_to_email.py
echo “Converted telegram_to_email.py.rtf to telegram_to_email.py” fi

# 3. Rename .save files if they exist and look like Python scripts for file in *.py.save; do
[ -e “$file” ] || continue
newname=$(echo “$file” | sed ‘s/\.save$//’)
mv “$file” “$newname”
echo “Renamed $file to $newname”
done

# 4. Make sure Python 3 is installed
if ! command -v python3 &> /dev/null; then
echo “Python3 not found. Installing with Homebrew…”
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)” brew install python
fi

# 5. Run all .py files in the folder
for script in *.py; do
echo “Running $script…”
python3 “$script”
done

Leave a comment