Created
March 14, 2025 13:11
-
-
Save kvdesa/de4d35b1cdf10f2bfa49267174018d4c to your computer and use it in GitHub Desktop.
Add custom commands to Xcode.app and all Xcode-*.app instances, use this every time you update/download a new Xcode.
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
# Add custom commands to Xcode.app and all Xcode-*.app instances. | |
# Run this every time you update/download Xcode. | |
function xcodeAddCustomCommands() { | |
PLB="/usr/libexec/PlistBuddy" | |
# First, update the standard Xcode.app if it exists | |
if [[ -d "/Applications/Xcode.app" ]]; then | |
echo "Xcode.app found, adding commands" | |
PLIST="/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/IDETextKeyBindingSet.plist" | |
if [[ -f "$PLIST" ]]; then | |
# Add the "Duplicate Current Lines Down" command | |
$PLB -c "Add :'Custom Commands':'Duplicate Current Lines Down' string 'selectParagraph:, delete:, yank:, moveToBeginningOfParagraph:, yank:, moveUp:, moveToEndOfParagraph:, moveToEndOfLine:'" "$PLIST" | |
# Assign Command+D | |
$PLB -c "Add :'Custom Commands':'Duplicate Current Lines Down':KeyEquivalent string 'd'" "$PLIST" | |
$PLB -c "Add :'Custom Commands':'Duplicate Current Lines Down':ModFlags integer 1048576" "$PLIST" | |
# Add the "Delete Current Line" command | |
$PLB -c "Add :'Custom Commands':'Delete Current Line' string 'deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToEndOfLine:'" "$PLIST" | |
# Assign Command+Backspace | |
$PLB -c "Add :'Custom Commands':'Delete Current Line':KeyEquivalent string $'\x7F'" "$PLIST" | |
$PLB -c "Add :'Custom Commands':'Delete Current Line':ModFlags integer 1048576" "$PLIST" | |
fi | |
fi | |
# Then, update each Xcode-*.app | |
for xcodeFolder in /Applications/Xcode-*.app; do | |
if [[ -d "$xcodeFolder" ]]; then | |
echo "$xcodeFolder found, adding commands" | |
PLIST="$xcodeFolder/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/IDETextKeyBindingSet.plist" | |
if [[ -f "$PLIST" ]]; then | |
# Add the "Duplicate Current Lines Down" command | |
$PLB -c "Add :'Custom Commands':'Duplicate Current Lines Down' string 'selectParagraph:, delete:, yank:, moveToBeginningOfParagraph:, yank:, moveUp:, moveToEndOfParagraph:, moveToEndOfLine:'" "$PLIST" | |
# Assign Command+D | |
$PLB -c "Add :'Custom Commands':'Duplicate Current Lines Down':KeyEquivalent string 'd'" "$PLIST" | |
$PLB -c "Add :'Custom Commands':'Duplicate Current Lines Down':ModFlags integer 1048576" "$PLIST" | |
# Add the "Delete Current Line" command | |
$PLB -c "Add :'Custom Commands':'Delete Current Line' string 'deleteToBeginningOfLine:, moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToEndOfLine:'" "$PLIST" | |
# Assign Command+Backspace | |
$PLB -c "Add :'Custom Commands':'Delete Current Line':KeyEquivalent string $'\x7F'" "$PLIST" | |
$PLB -c "Add :'Custom Commands':'Delete Current Line':ModFlags integer 1048576" "$PLIST" | |
fi | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment