-
Notifications
You must be signed in to change notification settings - Fork 14
/
skim-tools.rb
65 lines (53 loc) · 2.06 KB
/
skim-tools.rb
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
65
# encoding: UTF-8
# researchr scripts relevant to BibDesk (the right one is executed from the bottom of the file)
$:.push(File.dirname($0))
require 'utility-functions'
require 'appscript'
# stores a link to the last screenshot taken, and the current PDF page. when export to the wiki happens, the picture is
# moved to the wiki media folder, and linked to the notes
def screenshot
dname = Document.name.get[0][0..-5]
a = File.open("/tmp/skim-#{dname}-tmp","a")
page = Document.get[0].current_page.get.index.get
curfile = File.last_added("#{Home_path}/Desktop/Screen*.png")
a << "#{curfile},#{page}\n"
growl("One picture added to wiki notes cache")
end
# pops up a dialogue which asks how many pages, and runs a CLI command (pdfmanipulate) which extracts a piece of the current
# PDF starting with the current page and the number of pages indicated forwards. Useful for extracting articles out of
# proceedings, etc.
def splitpdf
require 'pashua'
include Pashua
docu = Document.path.get[0]
dname = Document.name.get[0][0..-5]
page = Document.get[0].current_page.get.index.get
# configuring Pashua dialogue
config = "
*.title = researchr
fb.type = textfield
fb.default = 1
fb.label = Starting on page #{page}, how many pages to extract?\n
xb.type = checkbox
xb.label = last page number, instead of number of pages
db.type = cancelbutton
db.label = Cancel
db.tooltip = Closes this window without taking action\n"
pagetmp = pashua_run config
exit if pagetmp['cancel'] == 1
startpage = page.to_i
tmppage = pagetmp['fb'].to_i
if pagetmp['xb'] == "1"
endpage = tmppage
else
endpage = pagetmp['fb'].to_i + startpage - 1
end
outfile = "#{Downloads_path}/#{dname[0..-5]}-split.pdf"
`pdfmanipulate split "#{docu}" #{startpage}-#{endpage} -o "#{outfile}"`
puts "pdfmanipulate split \"#{docu}\" #{startpage}-#{endpage} -o \"#{outfile}\""
growl("File extracted and put in Downloads directory")
end
#### Running the right function, depending on command line input ####
Skim = Appscript.app('Skim')
Document = Skim.document
send *ARGV