batterseapower / scripts

Miscellaneous scripts shared between my computers

This URL has Read+Write access

scripts / amacs
100755 42 lines (36 sloc) 0.615 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
#!/usr/bin/perl
 
$pid = 0;
open I, "ps -axww -U $ENV{'USER'} |";
while (<I>)
{
   if (/Aquamacs Emacs/ && !/grep/)
{
if (/^\s*([0-9]+)\s/)
{
$pid = $1;
}
}
}
 
close I;
$args = "";
for my $f (@ARGV)
{
    if (! -e $f)
{
   system("touch \"$f\"");
}
$args .= "\"$f\" ";
}
 
# there is still an issue:
# if the sudo emacs is still open, it will
# call 'open' and open the files in the wrong
# emacs process.
 
if ($pid)
 {
   system("open -a /Applications/Aquamacs\\ Emacs.app $args");
 }
else
 {
   system("/Applications/Aquamacs\\ Emacs.app/Contents/MacOS/Aquamacs\\ Emacs $args &");
 }
 
exit;