Created
February 7, 2025 14:14
-
-
Save alexziskind1/2ee79770658b9f76ed1fb8d422b0f478 to your computer and use it in GitHub Desktop.
MacOS Quick Action File Diff code with options for VSCode FileMerge and Terminal Diff
This file contains hidden or 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/bash | |
| # We expect exactly two files | |
| if [ $# -ne 2 ]; then | |
| osascript -e 'display alert "Please select exactly two files." as critical' | |
| exit 1 | |
| fi | |
| # Use osascript to show a choice dialog (AppleScript). | |
| CHOICE="$(osascript <<EOT | |
| set userChoice to choose from list {"VSCode Diff", "FileMerge", "Terminal Diff"} ¬ | |
| with prompt "Select a diff method:" ¬ | |
| without empty selection allowed | |
| if userChoice is false then | |
| return "Canceled" | |
| else | |
| return item 1 of userChoice | |
| end if | |
| EOT | |
| )" | |
| if [ "$CHOICE" = "Canceled" ]; then | |
| exit 0 | |
| fi | |
| # Decide how to diff based on the user's choice | |
| case "$CHOICE" in | |
| "VSCode Diff") | |
| # Assumes 'code' is on PATH. If not, use the full path, e.g.: | |
| # /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code -d ... | |
| code -d "$1" "$2" | |
| ;; | |
| "FileMerge") | |
| # Adjust path if needed; this is the usual location for Xcode’s FileMerge: | |
| /usr/bin/opendiff "$1" "$2" | |
| ;; | |
| "Terminal Diff") | |
| # We'll do a unified diff and open the result in TextEdit | |
| diff -u "$1" "$2" | open -f -a TextEdit | |
| ;; | |
| *) | |
| echo "Unknown choice: $CHOICE" | |
| exit 1 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment