F-Script Anywhere is this amazing utility that lets you dynamically inject a complete F-Script environment into any Cocoa application at run-time. Kind of the ultimate tool to explore and take control of applications from the inside.
Unfortunately, the current version does not work on Snow Leopard… But we have a workaround! It is included in a new distribution that has just been made available: F-Script 2.0.1 (download).
It is very simple to use. I’ll show you how it works and how to automate it.
Injecting F-Script into an application
- Locate the F-Script framework on your disk. The F-Script framework is part of the F-Script distribution and is named “FScript.framework”. In the following, we assume you put it in /Library/Frameworks/
- Open the UNIX terminal and launch gdb by typing:
gdbNote that if gdb is not on your system, you can get it by installing the Xcode package provided on the installation DVD of Mac OS X.
- Attach gdb to the target application, using the “attach” instruction. For example, to attach to TextEdit type:
attach TextEdit - Load the F-Script framework into the target application by typing the following (we assume the F-Script framework is located at /Library/Frameworks/FScript.framework. Modify the command if this is not the case):
p (char)[[NSBundle bundleWithPath:@"/Library/Frameworks/FScript.framework"] load] - Add an F-Script menu to the target application by typing:
p (void)[FScriptMenuItem insertInMainMenu] - Let the application run by typing:
continue
An F-Script menu should now appear in the menu bar of the target application. Using it, you can access the injected F-Script environment and play with the application from the inside.

Automating the injection procedure
Those steps are easy to automate by defining a new gdb command. To have this new command permanently available in gdb, you can add its definition to a .gdbinit file (a text file) that you put in your home directory. Your .gdbinit file is automatically executed each time gdb is launched. Here is the command definition that you can put in your .gdbinit file:
define loadfs
attach $arg0
p (char)[[NSBundle bundleWithPath:@"/Library/Frameworks/FScript.framework"] load]
p (void)[FScriptMenuItem insertInMainMenu]
continue
end
This defines a command named loadfs that takes the name of the application you want to inject into as argument.
For example, to inject F-Script into TextEdit you can type the following in gdb:
loadfs TextEdit
This automates steps 3 to 6.
Thanks to Ken Ferry for suggesting this injection technique.
Philippe,
Kevin Ballard has done some spelunking into how 1Password may be loading its extension into Safari on Snow Leopard. I’m wondering if this or a similar technique might be a suitable mechanism for enabling F-Script Anywhere on arbitrary Cocoa apps.
Take a look at http://kevin.sb.org/2009/09/02/1password-extension-loading-in-snow-leopard/
Jay,
Thanks for the pointer. Snow Leopard is somewhat redefining the injection scene. F-Script Anywhere might someday reappear based on one of these new approaches. In the meantime, we have the gdb injection workaround, which works well.