Copyright 2004 by M. Uli Kusterer Tue, 30 Dec 1969 07:58:58 GMT Comments on article blog-helpful-xcode-user-scripts at Zathras.de http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm blog-helpful-xcode-user-scripts Comments witness_dot_of_dot_teachtext_at_gmx_dot_net (M. Uli Kusterer) witness_dot_of_dot_teachtext_at_gmx_dot_net (M. Uli Kusterer) en-us Comment 10 by mario http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment10 http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment10 Hi there and thank you for this great resource!

I would like to create a script that replaces the number within the following line of code, duplicate it and then paste it. (basically increment the numbers and paste)
[UIImage imageNamed:@"myImage1.png"],

How do I do that?
Comment 9 by Thomas Westfeld http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment9 http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment9 Thomas Westfeld writes:
This script can be used to strip of Apple's legal disclaimer from their sample code for better readability.
Comment 8 by Linus http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment8 http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment8 A naive and simple way of generating the implementation body for a declaration.
Select the declarations you want to generate a body for and run the script below.
It simply replaces the ';' with "{}". It is indeed simple, but good enough for me.


#! /usr/bin/python
# -*- coding: utf-8 -*-

import sys

print "".join(sys.stdin.readlines()).replace(";\n", "\n{\n}\n"),
Comment 7 by Uli Kusterer http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment7 http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment7 Uli Kusterer writes:
Julian, that one is neat. Short, sweet, and will log any object type. Would be interesting to see if one could do a localized search and try to determine the type of that variable, then also make it work for ints etc.
Comment 6 by Uli Kusterer http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment6 http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment6 Uli Kusterer writes:
Andy, that sounds like a neat idea, and Peter's command line tool looks like a good start. Would love to see what becomes of this. Along similar lines, I'd love a script that auto-adds method declarations to the @interface for a method I just declared in @interface. I.e. I write the implementation, leave the cursor somewhere nearby, start the script, and it finds the method signature, opens the header, finds the @implementation in there and inserts the prototype there.

It'd be even cooler to be able to do that from a call: Double-click opening bracket and it'll analyze the types of the parameters and generate the right signature, then create an empty implementation and interface declaration. But I guess for that one might need Clang to actually parse the code.
Comment 5 by Uli Kusterer http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment5 http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment5 Uli Kusterer writes:
Dirk, that's a neat script, though it's unfortunate that it needs to mark up the ivars in a way that requires changes to the actual code. I wouldn't be able to use this on many open source projects unless I can convince everyone to use it.
Comment 4 by Ross Carter http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment4 http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment4 Ross Carter writes:
I'm not a good typist, so I use user scripts to type things for me, like a divider:

#! /usr/bin/perl -w
# -- PB User Script Info --
# %%%{PBXName=NSLog}%%%
# %%%{PBXOutput=ReplaceSelection}%%%
use strict;
my $object = <<'SELECTION';
%%%{PBXSelectedText}%%%
SELECTION
chomp $object;
print "//-------------------------------------------------------
// xxxxxxxxxxxx
//-------------------------------------------------------
";
exit 0;

or logging the method selector:

(same as above but with:) print "NSLog(@\"%s\", _cmd);";

or localized strings:

print "NSLocalizedStringFromTable(@\"%%%{PBXSelectedText}%%%\", @\"TABLEGOESHERE\", @\"%%%{PBXSelectedText}%%%\")";

NSStringFrom (type re or ra to get autocompletion for Rect, Range, etc):

print "NSStringFrom";

and various pragmas, to promote consistency in how I organize code within a file:

print "#pragma mark -\n";
print "#pragma mark IBActions\n";
Comment 3 by Julián Romero http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment3 http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment3 Julián Romero writes:
I use this one a lot. It adds a log of the selected variable:

#! /bin/sh
echo -n 'NSLog(@"%%%{PBXSelectedText}%%% => %@", %%%{PBXSelectedText}%%%%%%{PBXSelection}%%%);'
Comment 2 by Andy Lee http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment2 http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment2 Here's a script idea I *think* should be doable but have been too lazy to try as yet: http://www.notesfromandy.com/2009/09/04/app-idea-extract-method-name-from-selected-text/
Comment 1 by Dirk http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment1 http://www.zathras.de/angelweb/blog-helpful-xcode-user-scripts.htm#comment1 Dirk writes:
You might also like this one that I originally developed for iPhone development but also work on Mac code. It handles all the property stuff which is quite redundant in Objective-C:

http://github.com/holtwick/xobjc