-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoterotags.pl
executable file
·64 lines (49 loc) · 2.19 KB
/
zoterotags.pl
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl -w
use DBI;
use strict;
# quit zotero safely using applescript...
system("osascript", "-e", "quit app \"Zotero\"");
my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<);
my $db = DBI->connect("dbi:SQLite:/Users/$username/Zotero/zotero.sqlite", "", "",
{RaiseError => 1, AutoCommit => 1});
# Gets a list of all items with attachments and will add macOS tags to indicate **which kind of object** it is (right now, article, book, or thesis)
my $items = $db->selectall_arrayref("select items.itemID, items.itemTypeID, typeName, itemAttachments.path from items, itemAttachments, itemTypes where itemTypes.itemTypeID = items.itemTypeID and items.itemID = itemAttachments.parentItemID and itemAttachments.path like '/Users/%';");
print "item types\n\n";
foreach my $item (@$items) {
my ($itemID,$itemTypeID,$typeName,$path) = @$item;
print $itemID;
print "\n";
print $typeName;
print "\n";
print $path;
print "\n-----\n";
if ($typeName eq "journalArticle") {
system("tag", "--add", "article", $path);
}
if ($typeName eq "book") {
system("tag", "--add", "book", $path);
}
if ($typeName eq "thesis") {
system("tag", "--add", "dissertation", $path);
}
}
print "\n\n------\n\nTAGS\n\n";
# Gets a list of all items with tags and adds macOS tags to indicate them...
my $itemsTags = $db->selectall_arrayref("select items.itemID, tags.name, itemAttachments.path from items, itemAttachments, itemTags, tags where items.itemID = itemAttachments.parentItemID and itemAttachments.path like '/Users/%' and itemTags.itemID = items.itemID and itemTags.tagID = tags.tagID");
foreach my $item (@$itemsTags) {
my ($itemID,$tagName,$path) = @$item;
print $itemID;
print "\n";
print $tagName;
print "\n";
print $path;
print "\n-----\n";
if ($tagName eq "important") {
system("tag", "--add", "important", $path);
}
}
system("open", "/Applications/Zotero.app");
#for typeName in $(sqlite3 ~/Zotero/zotero.sqlite "select items.itemID, items.itemTypeID, typeName, itemAttachments.path from items, itemAttachments, itemTypes where itemTypes.itemTypeID = items.itemTypeID and items.itemID = itemAttachments.parentItemID and itemAttachments.path like '/Users/%';"); do
# echo $typeName
# echo $path
#done