Import a file into currently selected group

In trying to convert a formated note (= html note) into a markdown note via Pandoc, I use the script below (borrowed many ideas from @pete31 from his excellent post in my previous post) . Almost everything works fine. I create the markdown file in the temp folder, but I cannot manage to import the file into the currently selected group in DT with this line:

import outputFileWithPath to (current group)

The file is not being imported.

This is the error message I get “missing value”:

import "'/private/var/folders/2x/qxvqtlqx0yb96ybs3ygql9380000gn/T/TemporaryItems/Bear vs'" to current group
		--> missing value

Also: How do I import and then delete the file in the temp folder? (aka: How do I move the file into DT’s currently selected database and group?)

Convert from HTML note to markdown via Pandoc

property pTitle : "DEVONthink Batch convert HTML to MD via Pandoc"

tell application id "DNtp"
		set selectedItems to selection
		repeat with selectedItem in selectedItems
			-- path of item
			set inputFileWithPath to quoted form of (path of selectedItem as string)
			-- name and extension
			-- set itemName to name of selectedItem	
			set itemName to name of selectedItem
			set itemType to type of selectedItem as string
			-- destination path
			-- > temp folder
			set destinationPath to POSIX path of (path to temporary items folder)
			-- output file: markdown file into DEVONthink
			set outputFileWithPath to quoted form of (destinationPath & itemName & ".md")
			-- convert via Pandoc
			-- shell command: 
			--    pandoc --atx-headers --from html --to markdown_strict -o OUTPUT_FILE  INPUT_FILE
			do shell script "/usr/local/bin/pandoc  --atx-headers --from html --to markdown_strict -o " & outputFileWithPath & " " & inputFileWithPath
			-- finally import the new html file
			-- >>> this ain't working <<<
			import outputFileWithPath to (current group)
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

In the script I linked in the other thread :wink: I used „indicate“ instead of „import“.

I remember there was something special with the temporary items folder, indicate and moving into the database afterwards didn‘t work for me so I had to delete the files:

tell application "Finder"
    delete file (POSIX file theOutputPath as alias)
end tell

Not sure but could be that „import“ fails because you’re using „quoted from of“ OutputPath. Did you try without it?

What‘s the difference?


Got it (from the DEVONthink dictionary):

indicate v : Indicate ('index') a file or folder (including its subfolders). If no type is specified or the type is 'all', then links to unknown file types are created too.
    indicate text : The POSIX path of the file or folder.
    [to record] : The destination group. Uses incoming group or group selector if not specified.
    [type all/‌chat/‌image/‌location/‌markup/‌pdf and postscript/‌quicktime/‌rich/‌script/‌sheet/‌simple] : Obsolete.
→ record

Edit 2

Even if I change my script to indicate (index) the file in the temp folder,

			-- finally import the new html file
			indicate outputFileWithPath to (display group selector)

I get an error message:

tell application "DEVONthink 3"
	display group selector
		--> parent id 2.147483645E+9 of database id 4
	indicate "'/private/var/folders/2x/qxvqtlqx0yb96ybs3ygql9380000gn/T/TemporaryItems/Bear vs'" to parent id 2.147483645E+9 of database id 4
		--> missing value
end tell
missing value

Edit 3: Problem is with temp folder indeed

Just tried to open the (existing) file in temp folder from terminal:

$ open '/private/var/folders/2x/qxvqtlqx0yb96ybs3ygql9380000gn/T/TemporaryItems/Bear vs'

I get an error message first, before the file opens in my default markdown editor:

Cannot open folder /private/var/folders/2x/qxvqtlqx0yb96ybs3ygql9380000gn/T/TemporaryItems

So the problem seems to be with the temp folder?

Problem with temp folder was only that it didn‘t move the file into the database with „consolidate“ thus the need to delete the file.

But in your case double quotes followed by single quotes doesn‘t look right:

indicate "'/ ...

It‘s a DEVONthink command, just use normal double quotes. You‘ve built your Output Path variable with „quoted form of“ but that‘ not needed here.

1 Like