UPDATE: This workflow no longer works on Mavericks due to a debugger change. See this post for details on a new version.
I wanted to use the very handy F-Script environment to snoop around inside an application. F-Script can be injected into running applications by using gdb, which of course works fine, but they also provide a services-menu item for performing the injection. Due to several changes in OS X 10.7 Lion, the automator workflow that came with F-Script to perform this did not work.
I reworked the injector service so it works on Lion and doesn't leave behind (or even create) any temp files.
Download “Inject-F-Script-into-application.zip”
Inject-F-Script-into-application.zip – Downloaded 6934 times – 63.58 KBInstallation is identical to the one that comes with F-Script, so follow their readme.
The automator workflow consists of two steps:
1. Run Applescript, with contents
tell application "System Events"
set pid to unix id of the first process whose frontmost is true
end tell
return "" & pid
This gets the PID of the active application and returns it as a string.
2. Run Shell Script (Shell: /bin/bash, Pass input: as arguments), with contents
cat << EOF | sudo -u`whoami` gdb -n -q
attach '$1'
p (char)[[NSBundle bundleWithPath:@"/Library/Frameworks/FScript.framework"] load]
p (void)[FScriptMenuItem insertInMainMenu]
detach
quit
EOF
Using the "here-document" feature of bash, lines 2-6 are sent as STDIN to GDB without using a temp file. The PID to attach is passed in as an argument from the previous block. Invoking GDB directly (without sudo) doesn't allow attaching to a process, presumably due to services sandboxing. Sudoing as the current user works fine and allows the attach to happen.
Very glad to see this easy services injection functionality restored on Lion.
Excellent!
muchas gracias