Archive for October, 2009

F-Script injected into the Finder:

Looking around with the object browser. Cocoa all over the place!

The NSApplication singleton and its delegate… So cute!

Have you ever seen the Finder’s Cover Flow from the inside? Look at that setFog: method on the IKImageFlowCell… Yummy!

Ultimate proof that the Finder makes use of bindings:

Seems that the names of the Finder specific classes start with ‘T’. Oh well…

Don’t click on that “switchToSimpleFinder” method or else…

That black Cover Flow background is boring. With F-Script, we can change it to something more disco!

Read Full Post »

Garbage collection

New in F-Script 2.0 is a fast, concurrent, generational garbage collector. It was a lot of work to implement. Fortunately, Apple did all of it, as F-Script 2.0 uses the new Objective-C garbage collector. As with Objective-C, when you run F-Script in GC mode you no longer have to manage retain counts and to care for cyclic references. You can still use F-Script in non-GC mode, which is needed if you want to interact with non-GC capable frameworks or libraries. A new option in the F-Script preference panel let you choose your memory management model. Finally, you can embed F-Script in GC or non-GC applications.

Garbage collection is performed concurrently, on its own thread. Another notable aspect is that it works both for objects and for raw memory buffers. Actually, for raw memory buffers, you can either use managed or unmanaged memory. F-Script 2.0 lets you use unmanaged memory as usual (i.e., with the malloc: method) and introduces new methods, in the FSPointer class, for dealing with managed memory. Features such as weak references, explicit GC control, etc. are all available from F-Script using the standard methods provided by Cocoa.


F-Script 2.0 provides 64-bit support. Benefits include:

  • Very large virtual address space
  • New Objective-C runtime (optimized message dispatching, zero-cost setup model for exceptions, etc.)
  • Ability to load 64-bit frameworks in F-Script and to embed F-Script in 64-bit applications

You can still run in 32-bit mode and you can use the F-Script framework in 64-bit and 32-bit applications.
The F-Script API itself now exposes both 64-bit and 32-bit capable interfaces, using Cocoa’s NSInteger, NSUInteger and CGFloat macros.

New object browser

The graphical object browser gains a new look and a number of enhancements. This includes:

  • Introspection of Objective-C 2.0 properties
  • Improved introspection of bindings
  • Direct access to the view hierarchy
  • Visual feedback when selecting graphical components on screen
  • Additional information about standards Cocoa objects
  • And more…

Companion article: Exploring Cocoa with F-Script
Discover the graphical object browser and object inspectors in this in-depth article.


If you are a Cocoa developer, you already know that the dynamic nature of Objective-C and Cocoa is what makes them so flexible and powerful. In terms of development tools, the power of a dynamic object-oriented environment like Cocoa translates into original tools like Interface Builder or F-Script, an open source project that is presented in this article. F-Script is an integrated set of tools that makes it possible to interactively explore and manipulate Cocoa objects as well as script them using new high-level programming techniques. This article shows you how to use some of its most impressive features and demonstrates how it can be a useful addition to your developer toolkit. Read more…

Dynamic Cocoa class creation

F-Script 2.0 makes it very easy to dynamically define new classes. At run-time, these dynamically generated classes are regular Cocoa classes that happen to execute F-Script code instead of compiled Objective-C code. They can be used from both F-Script and Objective-C. You can subclass existing Cocoa classes in F-Script and, as in Objective-C, define instance variables, instance methods and class methods. In addition, F-Script also supports defining class instance variables.

Companion article: Creating Cocoa Classes with F-Script


F-Script 2.0 provides a handy syntax for dynamically creating Cocoa classes on the fly. This is useful for quickly experimenting, prototyping and using Cocoa interactively, as well as for developing sophisticated programs. You can type a class definition in the F-script console, hit return and immediately start playing with your new class. This article provides a quick introduction to this feature. Read more…

System-wide scripting

F-Script 2.0 is able to control scriptable applications and graphically browse and interact with the applications scripting interfaces. This major new feature is based on the MAC OS X Scripting Bridge technology. For example, here is how you can connect to iTunes:

iTunes := SBApplication applicationWithBundleIdentifier:'com.apple.iTunes'

You can then manipulate iTunes from F-script. For example, here is how you make iTunes go to the next track:

iTunes nextTrack

Companion article: System-wide Scripting with F-Script
Learn how to script your applications with this tutorial.


Like AppleScript, F-Script can communicate with scriptable application, making it possible to automate processes using these applications and to create workflows spanning multiple applications. This system-wide scripting capability relies on a standard Mac OS X technology called the Scripting Bridge.
Basically, the scripting bridge allows manipulating scriptable applications as if they were Cocoa objects, automatically taking care of the communication details (e.g. creating and sending Apple Events). This allows using F-Script to manipulate other applications through their standard scripting interface. Read More…

Updated embedding and injecting capabilities

F-Script can be easily embedded into your own applications or dynamically injected at runtime into any running Cocoa application. Embedding is great for adding scripting or interactive object querying/manipulation capabilities to your applications, as well as for implementing parts of your apps with F-Script. Injecting is incredibly powerful when it comes to debugging or exploring the innards of applications. F-Script 2 comes with full support for the new plugin model of Interface Builder 3, allowing drag and drop of F-Script graphical components right into your application. F-Script 2 also includes updated injecting tools (aka F-Script Anywhere) which lets you inject a complete F-Script environment at run time into any Cocoa application.

Companion article: Embedding F-Script into Cocoa Applications


All F-Script functionalities are available through components which can be integrated into applications. This enables you to:

  • Program all or part of an application using the F-Script language.
  • Offer a scripting environment within your applications, allowing users to manipulate your business objects and to automate processes.
  • Interface F-Script with other tools.

Because F-Script and Cocoa share the same object model, integration is easy and advanced. Read more…

Refined syntax and class library

F-Script is a Smalltalk dialect. As such, its syntax is well suited to the manipulation of Objective-C objects, since Objective-C itself borrowed its messaging syntax from Smalltalk. F-Script 2.0 introduces several syntax refinements, including a handy notation for specifying dictionaries. Here is how an NSMutableDictionary instance with two entries looks like:

#{key1 -> value1, key2 -> value2}

There are other syntax enhancements including support for Unicode in string literals and a hexadecimal notation for numbers. Besides, the base class library has been refined, with new methods for dealing with collections, new globals for easy access to the standards IO streams, a new facility for comparing objects with the special nil value and some changes in the way test for object equality is performed. It is also worth noting the introduction of a new public class, FSAssociation, which represents associations between two objects, a “key” and a “value”, and is primarily used for specifying dictionary entries.

If you are not familiar with the F-Script syntax and fundamental elements, the two articles referenced below will get you up to speed in a breeze.

Companion article: Learn F-Script in 20 Minutes and Have Fun Playing with Core Image


In this article, our goal will be to produce a nice little animation using fancy Core Image effects. In doing so, we will learn the basics of F-Script. So install yourself comfortably in front of your Mac, download the latest F-Script version from http://www.fscript.org and enjoy the trip! Read more…

Companion article: Scripting Cocoa with F-Script


One important application of Cocoa’s openness is its integration with scripting languages. This is very useful because it allows for interactive use and easy gluing of Cocoa components. In this article I want to give you a taste of Cocoa scripting, and to show you the level of integration that you can expect. We will use F-Script, an open source scripting language for Cocoa, to build a little graphical application. Using F-Script, we will directly program against the Application Kit, which is the Cocoa object framework for graphical user interfaces. Read more…

Snow Leopard

F-Script 2 is compatible with both Leopard and Snow Leopard. It lets you directly access a number of the latest Mac OS X frameworks. And other ones are just a simple loading instruction away.

Companion article: Accessing Mac OS X Frameworks with F-Script


F-Script.app, the standalone F-Script environment, is automatically linked with a number of Mac OS X frameworks. This is convenient for quickly exploring Mac OS X’s capabilities and directly using the frameworks without any further configuration. Read more…

New project infrastructure

The source code for F-Script is now available at Github.

New group for support and discussions: http://groups.google.com/group/f-script/.

Read Full Post »

Switching in F-Script

There is no switch/case statement or method in F-Script and Smalltalk. Usually, switching is done by taking advantage of object polymorphism or by simply nesting ifTrue:IfFalse: messages. For example, here is some C pseudo code with a switch statement:

switch (aValue)
    case 1: doSomething1;
    case 2: doSomething2;   
    case 3: doSomething3;   

We can write equivalent code in F-Script using ifTrue:IfFalse: messages:

aValue = 1 ifTrue:[doSomething1] ifFalse:[
aValue = 2 ifTrue:[doSomething2] ifFalse:[
aValue = 3 ifTrue:[doSomething3]]]

Another possible technique is based on blocks and dictionary lookup. Basically, we construct a dictionary whose keys are the various cases’ values we want to check against and whose values are blocks of code to execute. We then do a lookup in the dictionary and execute the selected block. With our example, this gives:

cases := #{
  1 -> [doSomething1],
  2 -> [doSomething2],
  3 -> [doSomething3]
(cases objectForKey:aValue) value

Searching for Smalltalk switch case on the Web will get you to additional techniques and discussions on emulating switch statements.

Read Full Post »

F-Script 2.0.2 is now available at http://www.fscript.org/download/F-Script20091026.zip

This version improves integration with Snow Leopard and fixes a memory management bug in the F-Script class creation system when running in reference counting mode. You are advised to upgrade.

Read Full Post »