Created
October 5, 2012 16:21
-
-
Save noamross/3840801 to your computer and use it in GitHub Desktop.
Remove cover pages from PDFs and make links to sync recent additions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is set to run any time a new file is added to my "Papers" folder, using launchd | |
# 1 - Find papers with JSTOR or Science cover sheets and remove the first page | |
text1="kind:pdf Your use of the JSTOR archive indicates your acceptance of" #JSTOR papers | |
text2="kind:pdf is published weekly, except the last week in December" #Science papers | |
#Add more of these as you find text snippets that identify cover sheets from different publishers. Then add more loops belo | |
mdfind -0 -onlyin ~/Dropbox/Papers/ "$text1" | # mdfind is a mac-specific search utility | |
while IFS="" read -r -d "" file; do | |
noext="${file%\.*}" | |
/opt/pdflabs/pdftk/bin/pdftk "$file" cat 2-end output "$noext".tmp #pdftk can be downloaded at http://goo.gl/qgv0j | |
mv -f "$noext".tmp "$file" | |
done | |
mdfind -0 -onlyin ~/Dropbox/Papers/ "$text2" | | |
while IFS="" read -r -d "" file; do | |
noext="${file%\.*}" | |
/opt/pdflabs/pdftk/bin/pdftk "$file" cat 2-end output "$noext".tmp | |
mv -f "$noext".tmp "$file" | |
done | |
# 2 - Find the files added or modified in the last two weeks and make hard links in the "iA Papers" folder to sync with iAnnotate PDF | |
rm ~/Dropbox/iA\ Papers/*.* | |
cd ~/Dropbox/Papers/ | |
find . -mtime -14 -name "*.pdf" -exec ln -F {} ~/Dropbox/iA\ Papers/{} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't make it work with grep :
#!/bin/bash -xv
text1="If you wish to distribute" #Science papers
grep -l "$text1" .pdf |
while IFS="" read -r -d "" file; do
noext="${file%.}"
pdftk "$file" cat 2-end output "$noext".tmp
mv -f "$noext".tmp "$file"
done