Skip to content

Instantly share code, notes, and snippets.

@venj
Created December 31, 2011 14:21
Show Gist options
  • Save venj/1544115 to your computer and use it in GitHub Desktop.
Save venj/1544115 to your computer and use it in GitHub Desktop.
Inject F-Script to a named process. This script is based on the Inject F-Script service. Kinda useful when some apps do not provide the standard services menu.
#!/bin/bash
usage() {
echo Usage: `basename $0` Process_Name
}
if [ $# -ne 1 ]; then
usage
exit 1
fi
pid=$(pidof $1 | awk -F' ' '{print $1}')
if [ -z $pid ];then
echo No such process: $1
exit 255
fi
cat > /tmp/run_gdb << EOF
sudo -u `whoami` gdb --pid $pid --batch --nx --command=/dev/stdin << EOT
p (char)[[NSBundle bundleWithPath:@"/Library/Frameworks/FScript.framework"] load]
p (void)[FScriptMenuItem insertInMainMenu]
EOT
EOF
osascript -e "tell application \"System Events\"
set pid to $pid
end tell
do shell script \"sh /tmp/run_gdb \" & pid"
unset pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment