Strip JSTOR first page

September 13, 2008

This simple apple script will strip the first page of a jstor document. It requires Adobe Acrobat to be installed on your machine to run. Copy it in the script editor, save it as an application, and then add it to the Finder as a button.

on run
tell application "Finder"
if selection is {} then
quit
else
set finderSelection to selection as alias list
end if
end tell
deletepage(finderSelection)
end run


on open (theList)
deletepage(theList)
end open


on deletepage(listOfAliases)
repeat with eachitem in listOfAliases
tell application "Adobe Acrobat Professional"
activate
open eachitem
set Doc_Ref to the front document
delete first page
close Doc_Ref saving yes
end tell
end repeat
end deletepage


TextMate Emacs-like indentation (for R files)

November 11, 2007

If you use OS X, TextMate is hands down the best editor available for this platform. It integrate perfectly with the OS X environment. While the Project Window is probably the greatest thing about TextMate for the everyday user, its extensibility is what makes it a wonderful companion in editing.

The biggest complain I have about TextMate is that it does not handle indentation very well. I write a lot of R code and I am used to the indentation provided by ess (Emacs Speak Statistics). Frustrated, I decided to do something about it. After looking for option I realized that I could combine the feature of Emacs with those of TextMate to improve indentation. In practice I was able to use emacs (with ess) as beckend for the indentation. If you want to try follow the following steps:

1. Install ess (Emacs Speak Statistics) from http://ess.r-project.or in /usr/share/emacs/site-lisp;

2. In TextMate go to Bundles|Bundle Editor|Show Bundle Editor…

3. Create a new command, say Tidy

4. Add the following script:

#!/usr/bin/perl
my $in;
my $now = "tidyRcode";
my $file = "/tmp/tmptx_${now}.R";
my $eb=$ENV{'TM_BUNDLE_SUPPORT'};
open FILE, ">$file" or die "unable to open $file $!";
while () {
print FILE $_;
}
close(FILE);
`emacs -batch --eval "(require 'ess)" ${file} --eval '(indent-region (point-min) (point-max) nil)' -f ess-fix-miscellaneous -f save-buffer &> /dev/null`;
my $in = `cat ${file}`;
print $in;

5. Select the following options:

  • Input: Selected Text or Document;
  • Output: Replace Selected Text;
  • Key Equivalent: Shift+Cmd+H;
  • Scope Selector: source.r

You can see the picture below with my setting

TextMate Emacs-like indentation (for R files)

Now you are ready to go. While you are editing R code, simply select and press Shift+Cmd+H and you will see your code….the ess way.