Skip to content

Instantly share code, notes, and snippets.

@SMotaal
Forked from Saik0s/convert.sh
Created August 20, 2024 13:09
Show Gist options
  • Save SMotaal/badd1a98235b94baa78e6f282b894c33 to your computer and use it in GitHub Desktop.
Save SMotaal/badd1a98235b94baa78e6f282b894c33 to your computer and use it in GitHub Desktop.
This shell script converts a Google Chrome extension into a Safari web extension. It prints all available extensions, prompts the user for the chrome extension path and desired name, converts and builds safari extension for macOS, and opens the built app.
#!/bin/zsh
ext_root_path=~/Library/Application\ Support/Google/Chrome/Default/Extensions
find "$ext_root_path" -name "manifest.json" -print0 | while IFS= read -r -d '' file; do echo "\033[1;33m$file\033[0m"; echo "-----------------"; cat "$file" | nl -n ln | GREP_COLOR='01;30' grep --color=always '.*'; echo "-----------------"; done
# Prompt the user for the working directory path which is chrome extension root
read -p "Enter the chrome extension path(for example difoiogjjojoaoomphldepapgpbgkhkb/2.7.7_0): " workdir
# Prompt the user for the result app name
read -p "Enter the desired app name: " app_name
# Check if workdir and app name are empty
if [[ -z $workdir || -z $app_name ]]; then
echo "workdir and app name should not be empty"
exit 1
fi
workdir="$ext_root_path/$workdir"
# Remove existing directories
rm -rf "$workdir/safari-extension"
rm -rf "$workdir/safari-extension-build"
# Convert to Safari web extension
xcrun safari-web-extension-converter "$workdir" --project-location "$workdir/safari-extension" --force --no-open --app-name "$app_name"
# Build for macOS
xcodebuild -project "$workdir/safari-extension/$app_name/$app_name.xcodeproj" -scheme "$app_name (macOS)" -configuration Debug clean build CONFIGURATION_BUILD_DIR="$workdir/safari-extension-build"
echo "App available at $workdir/safari-extension-build"
open "$workdir/safari-extension-build/$app_name.app"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment