-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdt_import.sh
More file actions
executable file
·102 lines (83 loc) · 2.08 KB
/
Copy pathdt_import.sh
File metadata and controls
executable file
·102 lines (83 loc) · 2.08 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
# dt_import.sh : Import a file into a DT database. Options allow the
# type of file and the destination group to be specified.
# Copyright (c) 2006, Eric Fedel. Released under the BSD License.
# (http://home.earthlink.net/~efedel/code/devon_think/index.html)
HELP_STR="Usage: $0 -[A|C|F|I|L|M|P|Q|R|S|T|X] [-g group] [path]
Import File Type Options:
-A All/Any
-C Chat
-F Form
-I Image
-L Location
-M Markup
-P PDF
-Q Quicktime
-R Rich Text
-S Script
-T Simple
-X Sheet
Import Location options:
-g path Group to import into"
IMPORT_TYPE="all"
DEST_PATH="(get root of current database)"
while getopts ACFILMPQRSTX\?g: opt
do
case "$opt"
in
# Import File Flags
A) IMPORT_TYPE="all" ;;
C) IMPORT_TYPE="chat" ;;
F) IMPORT_TYPE="form" ;;
I) IMPORT_TYPE="image" ;;
L) IMPORT_TYPE="location" ;;
M) IMPORT_TYPE="markup" ;;
P) IMPORT_TYPE="PDF" ;;
Q) IMPORT_TYPE="quicktime" ;;
R) IMPORT_TYPE="rich" ;;
S) IMPORT_TYPE="script" ;;
T) IMPORT_TYPE="simple" ;;
X) IMPORT_TYPE="sheet" ;;
# Group to import into
g) DEST_PATH="(get record at \"$OPTARG\")";;
\?) 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))
IMPORT_PATH=$1
# Input validation
if [ -z "$IMPORT_PATH" ]
then
echo "ERROR: path cannot be empty"
exit 3
fi
# Applescript for import
VAR=`osascript <<EOF
on import_file(in_path)
set nl to "\\\\\\\\n" -- newline (escaped)
tell application "DEVONthink Pro"
set g to $DEST_PATH
-- check that dest group exists
try
get g
on error msg
return "ERROR: Unable to find " & location of g & name of g & ": " & msg & nl
end try
try
set r to import in_path to g type $IMPORT_TYPE
on error msg
return "ERROR: Unable to import " & in_path & ": " & msg & nl
end try
set out to location of r & name of r & "|" & (id of r) as text & nl
end tell
return out
end
set result to import_file(POSIX file "$IMPORT_PATH")
EOF`
echo -ne $VAR