Skip to content

Instantly share code, notes, and snippets.

@mrfabbri mrfabbri/fscript-inject.sh
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.