A helper UserScript for Xcode

External developers... This forum's for you!

A helper UserScript for Xcode

Postby Dave_Higgins » Tue Sep 28, 2010 11:23 am

I got tired of going through the motions the long way with setting up SuperCard as a Custom Executable and tracking down my clippings of launch argument strings, so I made up an AppleScript to place into the User Scripts in Xcode. I thought I'd share it. Maybe it'll make somebody's next external a little easier to set up. 8-)

Setup: Save this to disk wherever you want (just as a script (.scpt)), and in Xcode, select Script menu (the script icon) > Edit User Scripts... and drag your saved script file from Finder into that list.

Usage: Start up a new Xcode project using one of the SuperCard templates, make sure it's the front project, then select it in the User Scripts menu.

I've included some comments for those that might be new to Xcode and/or AppleScript. As is, it sets up the launch arguments to match what's in the IT guide pdf file.

Code: Select all
using terms from application "Xcode"
   set tProject to project of active project document
   tell tProject
      set tEXE to make new executable
      
      ----       If your path to SuperCard is different, make that change here.
      set the name of tEXE to "SuperCard"
      set the path of tEXE to "/Applications/SuperCard 4.63/SuperCard 4.6.app"
      tell tEXE
         set tArg to make new launch argument
         set name of tArg to "load\\ external\\ \\\"$(PROJECT_DIR)/$(BUILD_DIR)/$(CONFIGURATION)/$(PROJECT_NAME).bundle\\\""
         set active of tArg to true
         
         
         set tShell to do shell script "echo $SHELL"
         if tShell = "/bin/tcsh" then
            set tArgString to "alert\\ $(PROJECT_NAME)\\(\\\"\\?\\\"\\)\\ explain\\ $(PROJECT_NAME)\\(\\\"!\\\"\\)"
         else -- I only know about /bin/bash and/or /bin/sh ... Other startup shells may need other escaping
            set tArgString to "alert\\ $(PROJECT_NAME)\\(\\\"?\\\"\\)\\ explain\\ $(PROJECT_NAME)\\(\\\"!\\\"\\)"
         end if
         set tArg to make new launch argument
         set name of tArg to tArgString
         set active of tArg to true
         
         
         ----      You can, of course, comment out the "alert" block above if you want to add your own command.
         ----      For instance, I have a single word command in my sharedFile ("xTestProject") that opens a project
         ----      that is designed for testing my externals.
         
         --          set tArg to make new launch argument
         --          set name of tArg to "xTestProject"
         --          set active of tArg to true
         
         ----      Just remember that if you use a longer string as your launch argument (name of tArg),
         ----      you'll need to escape spaces, parenthesis, quotes, etc... Keep in mind that in this AppleScript,
         ----      you'll need to add TWO backslashes for everything except quotes, which will require THREE (two for
         ----      escaping into one that will end up before the quote, + one more to escape the quote itself while inside
         ----      this AppleScript string).
         
         ----      Compare the strings below to see how that's done.
         
         ----      The string as it appears in Xcode (/bin/tcsh version. The "?" is escaped, whereas
         ----      /bin/sh version does not need the escape for "?"):
         ----      "alert\ $(PROJECT_NAME)\(\"\?\"\)\ explain\ $(PROJECT_NAME)\(\"!\"\)"
         ----
         ----      The string as it appears in AppleScript (double-escaped):
         ----      "alert\\ $(PROJECT_NAME)\\(\\\"\\?\\\"\\)\\ explain\\ $(PROJECT_NAME)\\(\\\"!\\\"\\)"
         
      end tell
   end tell
end using terms from
Last edited by Dave_Higgins on Fri Oct 01, 2010 5:37 pm, edited 2 times in total.
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

Re: A helper UserScript for Xcode

Postby codegreen » Tue Sep 28, 2010 9:37 pm

Dave Higgins wrote:I got tired of going through the motions the long way with setting up SuperCard as a Custom Executable and tracking down my clippings of launch argument strings, so I made up an AppleScript to place into the User Scripts in Xcode. I thought I'd share it.

Sweet!

Thanks,
-Mark
codegreen
 
Posts: 1510
Joined: Mon Jul 14, 2008 11:03 pm

Re: A helper UserScript for Xcode

Postby Dave_Higgins » Tue Sep 28, 2010 10:53 pm

mark wrote:Sweet!

:cheers:

Heh. I figured you'd have a bunch of scripts loaded into Xcode.

You can really write up some quite sophisticated User Scripts in AppleScript. In searching around for examples and proper syntax I've come across some scripts that people are using that set up things like create/manage groups, move files around within groups, set any of the build settings, add existing files/frameworks/libraries to a project, clean/build/debug, and of course manipulate the text within any one file.

One thing to note about the "Edit User Scripts..." window... The "Duplicate" option under the + button only duplicates the reference to an AS file (sorta like making an alias to it in the list). I found this out the hard way when I just duplicated one, thinking that it would make a copy of the AS file in the same folder as the original, then I erased it all and placed my new script in it (which I worked up in AS Script Editor). Come to find out, I was working with one AS file, but accessing it with two or three entries in the list. Needless to say I ended up losing that original script data.
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon

Re: A helper UserScript for Xcode

Postby vinnie-bob » Wed Sep 29, 2010 5:13 am

Hey Dave,

Since you are playing with ObjC, Cocoa and you know applescript, have you tried anything with ApplescriptObjC? (The replacement for Applescript studio?) Unfortunately, there isn't much documentation out there and you need to know ObjC classes and bindings, but looks promising. MacScripter has some nice tutorials on their website in the "Unscripted" section/archives.

Vince
------
vince
------
User avatar
vinnie-bob
 
Posts: 218
Joined: Sun Jul 06, 2008 10:55 am
Location: Des Moines, Iowa, USA

Re: A helper UserScript for Xcode

Postby Dave_Higgins » Wed Sep 29, 2010 11:01 am

vince wrote:Since you are playing with ObjC, Cocoa and you know applescript, have you tried anything with ApplescriptObjC?


Oh yeah. I spent a good solid few weeks in it before I started doing much with pure Obj-C. For me (YMMV), it was a good way to break into it. Before all that I would look at sample Obj-C code and just see mush... As Uli said to me in a chat... Newbie sees "Brackets!!! Brackets Everywhere!!!"
shoot_me

What helped for me, starting with ASOC, was not having to deal with separate .m/.h files... Not having to use IBOutlets and funky variations for @property and the like. And the parameter setup was more familiar to me coming out of SC (function name, then params in one group, separated with commas)...
method_with_params_(param1, param2, param3)
as opposed to
method:param1 with:param2 params:param3
and the docs always showing the type of each param:
- (NSString *)method:(NSString *)param1 with:(NSArray *)param2 params:(NSDictionary *)param3
Pure madness for an old fart who's had SC burned into the brain for years. I certainly was no expert in AppleScript, though, going into it. I had to spend a lot of time working around the Cocoa/Obj-C aspect of it and learning some of the AppleScript way of doing things (dealing with strings, items, lists, etc...). I did get a boost when I came across an ASOC project that Terry Heaford built.

Another thing that helped by starting with ASOC, coming out of SC, is the flexibility when it comes to syntax in ASOC. For instance, in Obj-C, if you want to send a message to an object, you would use something like [myTextView insertText:aString]; .... This would be like SC's "put aString into fld myTextView", or "set the text of myTextView to aString" (without the text insertion pointer being active in the field)... In ASOC you have a few options:
Code: Select all
myTextView's insertText_(aString)

tell myTextView to insertText_(aString)

tell myTextView
  insertText_(aString)
end tell

For me, I would end up using the second or third version as it felt more SC-like, in the direction of send "insertText" && aString to fld "myTextView", with an "insertText" handler being in the field's script.

One hurdle that I had to overcome was the terminology used in Obj-C. "Methods"... at the start, to me, it was like calling everything in SC "commands", no matter if it's an instruction to perform an action, or if it's a function that returns a value. And "Class", "Objects"... To me, an object was something you could place on a card or bg... a button, field, or grc... In Obj-C you can do things like (in psudo-ST) send "someCommand" to line 1 of fld "aField", and it would act as if line 1 of fld "aField" has it's own script with it's own "on someCommand" handler. Was hard to wrap my head around.

Another nice thing is that ASOC apps can talk to SC very easy since you can mix plain-ol-AppleScript right into the source (tell application "SuperCard......"). It's just too bad it's limited to Snow Leopard, though.

vince wrote:Unfortunately, there isn't much documentation out there and you need to know ObjC classes and bindings, but looks promising. MacScripter has some nice tutorials on their website in the "Unscripted" section/archives.

Yeah. I still tune in to the ASOC forum there. It's not real busy, but they've been helpful. That Shane Stanley there is pretty sharp when it comes to helping people out. What few samples are out there tend to rely on you already knowing Obj-C, so it just shows a comparison, instead of teaching a little bit of Obj-C (using AS syntax) along the way.

If you're thinking of giving it a try, a document that helped me out A LOT in "getting it" when it comes to Obj-C (either straight up, or with ASOC), is http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html%23//apple_ref/doc/uid/TP30001163.
My two favorite teams are Detroit and whoever's playing Chicago.
User avatar
Dave_Higgins
 
Posts: 454
Joined: Mon Jul 07, 2008 9:50 am
Location: Dark Side Of The Moon


Return to Xcode and the Internals Toolbox

Who is online

Users browsing this forum: No registered users and 1 guest