Skip to content

Instantly share code, notes, and snippets.

@JohnTheBastard
Created November 19, 2015 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnTheBastard/334166fde4dd26c52b4a to your computer and use it in GitHub Desktop.
Save JohnTheBastard/334166fde4dd26c52b4a to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
$pid = 0;
open I, "ps -axww -U $ENV{'USER'} |";
while (<I>)
{
if (/Aquamacs/ && !/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/Aquamacs.app $args");
}
else
{
system("/Applications/Aquamacs/Aquamacs.app/Contents/MacOS/Aquamacs $args &");
}
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment