Skip to content

Instantly share code, notes, and snippets.

@mrfabbri
Last active August 29, 2015 14:11
Show Gist options
  • Save mrfabbri/9d2a649c036b1b3d7b6b to your computer and use it in GitHub Desktop.
Save mrfabbri/9d2a649c036b1b3d7b6b to your computer and use it in GitHub Desktop.
F-Script injection script
#!/usr/bin/env zsh
Frameworks="/Library/Frameworks";
usage() {
echo "Injects F-Script (menu) into a running application (via lldb)"
echo "usage: $(basename $0) [-c] <application-name-or-PID>"
echo
echo "options:"
echo "-c \t\topens F-Script console (useful for apps lacking a menu bar):"
echo
echo "note: FScript.framework should be installed in ${Frameworks}";
exit 2;
}
check_framework() {
if test ! -d "${Frameworks}/FScript.framework";
then
echo "FScript.framework not found in ${Frameworks}"
echo "Download from http://www.f-script.org or https://github.com/Kentzo/F-Script";
exit 1;
fi
}
inject() {
check_framework;
echo "Injecting F-Script into " $1;
cat << EOF | lldb;
attach $1
expr (void) [[NSBundle bundleWithPath:@"${Frameworks}/FScript.framework"] load]
expr FScriptMenuItem *\$menuItem = [FScriptMenuItem alloc]
expr [\$menuItem init]
expr (void) [[[NSApplication sharedApplication] mainMenu] addItem:\$menuItem]
${CONSOLE}
detach
quit
EOF
}
with_console() {
read -r -d '' CONSOLE << EOF
expr [\$menuItem openObjectBrowser:nil]
expr [\$menuItem showConsole:nil]
EOF
}
while getopts hc o; do
case "$o" in
h) usage;;
c) with_console;;
[?]) usage;;
esac
done
shift $OPTIND-1
if (test $# -ge 1); then
1="$*"; inject $1;
else
usage;
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment