Last active
December 9, 2024 08:11
-
-
Save Saik0s/5beec651555332b627524cb7d83ebec5 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.
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 | |
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