-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdt_get_id.sh
executable file
·58 lines (44 loc) · 1 KB
/
dt_get_id.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
#!/bin/sh
# dt_get_id.sh : Get the id of a record in the DT database based on its path.
# Copyright (c) 2006, Eric Fedel. Released under the BSD License.
# (http://home.earthlink.net/~efedel/code/devon_think/index.html)
HELP_STR="Usage: $0 path"
while getopts \? opt
do
case "$opt"
in
\?) echo "$HELP_STR"; exit 1;;
esac
done
if [ $((OPTIND)) -gt $# ]
then
echo "ERROR: path argument is mandatory"
exit 2
fi
# Get Params
shift $((OPTIND - 1))
REC_PATH=$1
# Input validation
if [ -z "$REC_PATH" ]
then
echo "ERROR: path cannot be empty"
exit 3
fi
# Applescript for get_id
VAR=`osascript <<EOF
set nl to "\\\\\\\\n" -- newline (escaped)
on get_record(path_str)
tell application "DEVONthink Pro"
set r to get record at path_str
-- check that record exists
try
get r
on error msg
return "ERROR: Unable to find " & path_str & ": " & msg & my nl
end try
return id of r as text & my nl
end tell
end
set result to get_record("$REC_PATH")
EOF`
echo -ne $VAR