Here is a tool that will automatically rename the most recently downloaded PDF with the most recently entered Zotero entry. You may call it directly from the browser by setting a link in the toolbar to file:///c:/system/test.000 while setting the file association for 000 in the Content tab to the location of ZoteroRename.exe.
ZoteroRename.zip includes the source perl script including a compiled windows version.
my $sql = 'SELECT DISTINCT items.itemID
FROM items
WHERE items.itemTypeID=4
ORDER BY items.dateAdded DESC
LIMIT 1';
$res0 = $dbh->selectall_arrayref($sql);
$ID = $res0->[0][0];
my $sql = 'SELECT DISTINCT itemDataValues.value
FROM items LEFT JOIN itemData ON items.itemID = itemData.itemID LEFT JOIN itemDataValues ON itemData.valueID = itemDataValues.valueID
WHERE items.itemID=' . $ID . ' AND itemData.fieldID IN (14,12)';
$res1 = $dbh->selectall_arrayref($sql);
$dt = $res1->[1][0];
$dt =~ s/(^[0-9]{4})(.*)/\1/gi;
$so = $res1->[0][0];
$so =~ s/\s//gi;
my $sql = 'SELECT DISTINCT creators.lastName
FROM items LEFT JOIN itemCreators ON items.itemID = itemCreators.itemID LEFT JOIN creators ON itemCreators.creatorID = creators.creatorID
WHERE items.itemID=' . $ID . ' AND itemCreators.orderIndex=0';
$res2 = $dbh->selectall_arrayref($sql);
$nm = $res2->[0][0];
$newfn = "$nm-$so-$dt.pdf";
my $dir_handle = new DirHandle $dir or die "unable to open $dir $!";
my %newest;
$newest{mtime} = 0;
while (defined($file = $dir_handle->read)) {
next if ($file eq '.' or $file eq '..');
my $mtime = (stat("$dir/$file"))[9];
$newest{file} = $file and $newest{mtime} = $mtime if $newest{mtime} < $mtime;
}
Hint for Windows Users: I did not get the compiled exe to work, but if you have a perl interpreter (eg. activeperl) the perl script works fine from the command line: perl (path to ZoteroRename.pl) (path to Zotero.sqlite) (path to folder with new pdf file). Then the newest file in the folder ist renamed to author-journal-year.pdf.
a few questions:
1. does it maintain the link in Zotero or do you have to re-associate the file?
2. can you make it rename ALL the pdfs?
3. any way to make this into a Zotero extension or a Firefox extension?
I still do not fully understand how to use this plugin. But it seems to be very useful.
Can you elaborate a little bit?
Thanks, this was almost exactly what I needed!
Sounds like a really great addition. I am, however, not sure how to use it. Can you please explain in some more detail how I have to set the tool up.
Thanks!
hello. I think this is absolutely marvelous but I couldn’t get this to work. Could you please leave a hint for us non-perlers how to use this thing?
I tried reading the code but it doesnt make any sense.
Hint for Windows Users: I did not get the compiled exe to work, but if you have a perl interpreter (eg. activeperl) the perl script works fine from the command line: perl (path to ZoteroRename.pl) (path to Zotero.sqlite) (path to folder with new pdf file). Then the newest file in the folder ist renamed to author-journal-year.pdf.
-junin
this sounds perfect!
a few questions:
1. does it maintain the link in Zotero or do you have to re-associate the file?
2. can you make it rename ALL the pdfs?
3. any way to make this into a Zotero extension or a Firefox extension?