-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdt_export.sh
executable file
·75 lines (57 loc) · 1.37 KB
/
dt_export.sh
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
66
67
68
69
70
71
72
#!/bin/sh
# dt_export.sh : Export a record from a DT database based on its ID.
# Path to which the record will be exported is required.
# Copyright (c) 2006, Eric Fedel. Released under the BSD License.
# (http://home.earthlink.net/~efedel/code/devon_think/index.html)
HELP_STR="Usage: $0 record_id output_path"
while getopts \? opt
do
case "$opt"
in
\?) echo "$HELP_STR"; exit 1;;
esac
done
if [ $((OPTIND + 1)) -gt $# ]
then
echo "ERROR: record_id and output_path arguments are mandatory"
exit 2
fi
# Get Params
shift $((OPTIND - 1))
REC_ID=$1
REC_PATH=$2
# Input validation
echo $REC_ID | grep '[^0-9]'
if [ $? -eq 0 ]
then
echo "ERROR: record_id must be an integer"
exit 3
fi
if [ -z "$REC_PATH" ]
then
echo "ERROR: output_path must be non-NULL"
exit 4
fi
# Applescript for export
VAR=`osascript <<EOF
set nl to "\\\\\\\\n" -- newline (escaped)
on export_record(r_id, out_path)
tell application "DEVONthink Pro"
set r to get record with r_id
-- check that record exists
try
get r
on error msg
return "ERROR: Unable to find " & r_id as text & ": " & msg & my nl
end try
-- export record
try
export record r to out_path
on error msg
return "ERROR: Unable to write " & out_path & ": " & msg & my nl
end try
end tell
end
set result to export_record($REC_ID, "$REC_PATH")
EOF`
echo -ne $VAR