Skip to content

Instantly share code, notes, and snippets.

@diego898
Last active May 4, 2018 11:34
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save diego898/e117cc4aec51511f39d5611a0a65f946 to your computer and use it in GitHub Desktop.
This is a set of files to watch a directory where I place PDFs of papers and automatically create a corresponding tiddler for that paper.

This is a set of files to watch a directory where I place PDFs of papers and automatically create a corresponding tiddler for that paper.

  • Edit TW_LOC, TID_DEF_TAGS, and TID_TEXT in the bash script
  • Edit location of bash script in .scpt file
  • place the .scpt file in ~/Library/Scripts/Folder Action Scripts/
  • make sure you have a default program to open the .tid extension (if you want to keep the open line)
  • this uses gdate from coreutils to get the timestamp right
  • right click on the folder you want to watch and add a new folder action, selecting the .scpt file
  • make sure the shell script is executable
#!/bin/bash
# EDIT THESE!
TW_LOC=/Users/myname/mywiki/tidders
TID_DEF_TAGS="tag1 tag2 [[tag 3]]"
TID_TEXT="defaul text"
if [ "$1" == "" ]; then
TID_TITLE="temp"
else
TID_TITLE="$1"
fi
if [ "$2" == "" ]; then
TID_TAGS="$TID_DEF_TAGS"
else
TID_TAGS="$TID_DEF_TAGS $2"
fi
while getopts ":t:a:" opt; do
case $opt in
t) TID_TITLE="$OPTARG"
;;
a) TID_TAGS="$TID_DEF_TAGS $OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
if [ ! -f "$TW_LOC/$TID_TITLE.tid" ]; then
echo -e "Creating new empty tiddler with name: $TID_TITLE.tid"
echo -e "created:" `/usr/local/bin/gdate -u +%Y%m%d%H%M%S%3N`"\nmodified:" `/usr/local/bin/gdate -u +%Y%m%d%H%M%S%3N`"\ntags: $TID_TAGS\ntitle: $TID_TITLE\ntouched:" `/usr/local/bin/gdate -u +%Y%m%d`"\ntype: text/vnd.tiddlywiki\n\n$TID_TEXT" > "$TW_LOC/$TID_TITLE.tid"
open "$TW_LOC/$TID_TITLE.tid"
else
echo "Error - file with name $TID_TITLE.tid already exists."
fi
on adding folder items to thisFolder after receiving theseItems
repeat with i from 1 to count theseItems
try
set thisItem to item i in theseItems
set thisItemsInfo to info for thisItem
set thisItemsFileName to quoted form of displayed name in thisItemsInfo
tell application "Finder"
set {_filename, _extension, _ishidden} to the {displayed name, name extension, extension hidden} of thisItem
end tell
if (_extension missing value) then
set baseName to quoted form of text 1 thru -((length of _extension) + 2) of _filename
end if
do shell script "/EDITHIS/location/of/newPaperTid -a '[[EDIT THIS]]' -t " & baseName
end try
end repeat
end adding folder items to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment