Grayson / nusomewhere

A GUI for NuAnywhere.

nusomewhere / nu-anywhere
100755 44 lines (37 sloc) 1.455 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/local/bin/nush
#
# nu-anywhere
# This script injects a Nu Console into a running Cocoa application.
#
# This script must be run as root.
#
# Because paths to the framework and bundle are hard-coded,
# this script must be run from the current directory.
#
# The application must already be running.
#
# Usage: sudo nu-anywhere <application>
#
# Examples: sudo nu-anywhere "Address Book"
# sudo nu-anywhere Safari
#
 
# Changes for NuSomewhere:
# Changes the load command and the NuConsole bundle so that it reads from the current directory for each.
# Also adds injection of the NuInspect bundle.
 
(load "NuInject")
 
(set bundle "NuInspect.bundle") ;; this is the bundle to inject
 
;; add something useful to NSString
(class NSString
     (- split is ((self componentsSeparatedByString:" ") select: (do (x) (!= x "")))))
 
;; the application name is (argv 0), the first argument to the script. We want its pid.
(set argv ((NuApplication sharedApplication) arguments))
(set ps (NSString stringWithShellCommand:"ps auxww | grep '#{(argv 0)}' | grep -v grep | grep -v nu-anywhere"))
(set fields (ps split))
 
(if (> (fields count) 2)
    (then
          (set pid ((fields 1) intValue))
          (puts "Injecting #{bundle} into #{(argv 0)}, process #{pid}.")
          (Nu injectBundleWithPath:bundle intoProcess:pid)
          (puts "Injection complete."))
    (else
         (puts "Unable to find pid for #{(argv 0)}.")))