Script Fails When Run From DT Script Menu?

Here’s an interesting one that I haven’t been able to figure out yet:

I received a comment on Veritrope.com from someone who was having an unusual problem with my Evernote-to-DEVONthink script… http://veritrope.com/tips/evernote-devonthink-export/2 (source here) :

Sure enough, I was able to replicate this… but I haven’t been able to determine the cause! Since this is being initiated via the DEVON script menu, I don’t have my usual debugging tools – but GROWL messages suggest that this is Finder-related.

Anyone have an idea why a script would work if run from the AppleScript Editor but fail if run from DEVONthink Pro’s script menu?

Sorry – hope you don’t mind if I give this post a bump!

Still trying to resolve this issue… anyone have any ideas of why a script would fail when run from DT’s internal script menu but work everywhere else?

Justin, it doesn’t fail 100% of the time. When run from the DTPO script menu it appears that your script will only import documents that were originally imported into Evernote as PDFs.

Don’t know why that would be the case - but I can repeat that behavior every time.

The script runs fine from AppleScript Editor and the regular script menu.

Korm:
Thanks for this – it’s a very interesting observation! (Now all I have to do is figure out a way to turn that observation into a “Dr. House”-like epiphany about how to fix this! :wink: )

Christian / Other DEVON Team Members:
Can you share a little more technical info about how the internal script menu works with us? Is there any reason that a script would run differently than in AppleScript Editor when initiated inside DEVONthink Pro?

Specifically, the portion of the script that Korm is referencing (the “PDF / Other File Discriminator” section) will successfully create and import a Webarchive when run externally, but not internally.

The bit in question follows a bit some code that looks through the exported note data from Evernote for a PDF file. It then goes here:


(*IMPORT PDF IF PRESENT... *)
tell application id "com.devon-technologies.thinkpro2"

if itemexists is true then
	set resultRecord to import thePDF ¬
	name SelNote ¬
	to theGroup ¬
	type "PDF"
						
(*.. OR CONVERT TO WEBARCHIVE FILE*)
else
tell application "Finder"
	set ExportedNote to POSIX path of ((ArchiveInput & ":" & CleanTitle & ".html") as string)
	do shell script ("textutil -convert webarchive " & (quoted form of ExportedNote))
	set Make_Archive to POSIX path of ((ArchiveInput & ":" & CleanTitle & ".webarchive") as string)
end tell

set resultRecord to import Make_Archive ¬
        name SelNote ¬
	to theGroup ¬
	type html

end if
end tell

Thoughts?

It should more or less work like executing scripts via the Script Editor. The only differences might be so-called coercions necessary for Automator. In addition, compiled scripts are cached but that shouldn’t cause any troubles.

As I don’t use EverNote (suprising, isn’t it? :wink:) and therefore don’t have useful data to convert, could you send me some samples to reproduce this? Thanks!

Not surprised at all… but, since this script is all about bringing Evernote items into DEVON, you should suffer no karmic penalty for your debugging efforts! :wink:

What Korm is saying is “Only PDFs work!” — so no special sample data should be needed. Just try to import any non-PDF note (text, HTML, etc.) from Evernote into DTP using the internal menu to initiate.

Didn’t try your script, but I’d look at:

to make sure that “textutil” is really invoked.

Very likely the shell environment is different depending on whether the script is run from DTPO or Applescript editor. For example, how is the PATH variable set in either case?

HTH, Charles

It’s indeed a coercion issue but this snippet should be reliable:


tell application "Finder"
	set ArchiveInput to POSIX path of (ArchiveInput as alias)
	set ExportedNote to ArchiveInput & CleanTitle & ".html"
	set Make_Archive to ArchiveInput & CleanTitle & ".webarchive"
	do shell script "/usr/bin/textutil -convert webarchive " & (quoted form of ExportedNote) & " -output " & (quoted form of Make_Archive)
end tell

A Brief Follow-Up:
With the kind help of Christian, korm, and Charles (as well as my private testing group), we now have a script that works from DEVONthink Pro’s Script Menu!!! :smiley:

Link to Script:
http://veritrope.com/tips/evernote-devonthink-export

Version 1.3 applies the wisdom of this thread to the coercion issue and also fixes a couple of other bugs. New to this release – Created/Modified Dates from the original Evernote item are now populated into the new DEVONthink Pro note… and I’ve enabled support for tags as well (after manually enabling the feature within the script).

Thanks again to everyone here for your help!