F-Script icon indicating copy to clipboard operation
F-Script copied to clipboard

Inject F-Script into application requires gdb

Open abarnert opened this issue 11 years ago • 2 comments

Recent versions of Xcode no longer come with a gdb symlink, so you have to use lldb instead.

While lldb does have synonyms for its commands that make everything work, its command-line arguments are different. You have to use --source rather than -command, and if you use -n you have to give it an argument (which also makes things simpler, because now you can just pass the process name as an argument instead of having to hack up the script with sed—or just use -p with the PID, which means no quoting issues).

If you don't need admin privileges, the whole thing can be an AppleScript:

tell application "System Events"
    unix id of the first process whose frontmost is true
end tell

Then pass the result to a shell script with input as arguments:

lldb --attach-pid "$*" <<EOF
p (char)[[NSBundle bundleWithPath:@"/Library/Frameworks/FScript.framework"] load]
p (void)[FScriptMenuItem insertInMainMenu]
detach
quit
EOF

If you do, then you can remove the first line of gdbtemp.txt (and rename it to lldbtemp.txt while you're at it) and replace the existing AppleScript with:

tell application "System Events"
    set pid to unix id of the first process whose frontmost is true
end tell

do shell script "lldb -attach-pid" & pid & " --source=/tmp/lldbtemp.txt" with administrator privileges

Personally, I've created an fscript-inject shell script:

#!/bin/bash
lldb --attach-pid "$1" <<EOF
p (char)[[NSBundle bundleWithPath:@"/Library/Frameworks/FScript.framework"] load]
p (void)[FScriptMenuItem insertInMainMenu]
detach
quit
EOF

So my workflow is just one AppleScript:

tell application "System Events"
    set pid to unix id of the first process whose frontmost is true
end tell

do shell script "fscript-inject " & pid with administrator privileges

abarnert avatar Dec 18 '14 00:12 abarnert

@abarnert Nice, could you pack it in a file? I'll attach it to releases.

Kentzo avatar Dec 23 '14 12:12 Kentzo

Alternatively, you can use SIMBL. See my project

perfaram avatar Jun 22 '15 18:06 perfaram