The default Comment/Uncomment script in Xcode works for python and pearl only if the first line of your scripts is #! /... . However, most of the times this is not what I do for my python scripts. So we can change the default script so that it determines the type of file from the extension .py. To do so, go to the scripts tab in Xcode -the little icon before help- the select Edit User Scripts. Select the Comment/Uncomment scripts and change it to be:
#! /usr/bin/perl -w
#
# un_commentLines.pl -
Comments or uncomments the selected lines
#
Uses '# ' for Perl and shell scripts; '// ' otherwise
my $outputString = "";
my $perlCmt = "#";
my $cCmt = "//";
# get path to document
my $headerPath = <<'HEADERPATH';
%%%{PBXFilePath}%%%
HEADERPATH
chomp $headerPath;my $commentString;
if ($headerPath =~m/\.(sh|pl|py)$/) {
$commentString = $perlCmt;
} else {
$commentString = $cCmt;
}
my @selection =
; # read the selection from standard input
# no chars in selection, so create an empty selection
if (!@selection) {
push @selection, "";
};
# add or remove comment markers depending on the state of the first line of the selection
# if it is uncommented, comment all lines. If it is commented, remove comment markers, if present
my $firstLineOfSelection = $selection[0]; #get first line
my $addingCommentsString = 1;
if ($firstLineOfSelection =~ /^$commentString/) { #selection starts with comment
$addingCommentsString = 0;
}
foreach my $line (@selection) {
if ($addingCommentsString == 1) {
$outputString .= $commentString.$line;
} else {
$line =~ s/^$commentString//;
$outputString .= $line;
}
}
print "%%%{PBXSelection}%%%";
print $outputString;
print "%%%{PBXSelection}%%%";