Javascript instead of AppleScript

Hi there,

can someone help me to translate underneath script into javascript:

set DB to "Test2" -- This is the name of the database to be used
set dest to "/Test2 Inbox/New Group 4" -- This is the group to be used. Paths for group locations MUST be entered in this fashion.

tell application id "DNtp"
   if DB is not in (name of databases) then -- You need to check if the database is open.
      display alert "Database " & DB & " is not open!" & return & return & "Please open it."
      set destinationGroup to get record at dest in database DB -- You need to specify the database, otherwise the current database will be queried. A VERY likely scenario since you'd be working while Hazel works in the background
      set newRecord to (import theFile to destinationGroup)
      if (exists newRecord) then tell application "Finder" to delete theFile
   end if
end tell

I need to add a document to a specific group of a Devonthink Database. But for any reason, in Javascript, the document gets alway’s filed into the default group

Many thanks for your help


Welcome to the Forums!

I am curious why you’re wanting this in Javascript, when the AppleScript works as expected?

Hmm, very easy. I’m a newbie in Applescript and javascript and want to go with javascript for automation in the future due to better support from apple - hope this makes sense?

Understood, however, I would disagree about “better support” of Javascript from Apple. In fact, it’s much less supported and very poorly documented too. However, if you like the language go for it! :slight_smile:

Thanks for sharing your view. As I said at the beginning, I’m a newbie. Maybe I have to rethink and go with applescript

Best regards :sunglasses:

I too would argue that AppleScript is better supported by Apple than JavaScript.

However, the main reason to choose AppleScript is Late Night Software’s Script Debugger, an amazing tool that lets you single-step through your code and inspect the variables. You can also use it to browse the objects of every currently running app in its current state. This is invaluable for any non-trivial scripting project. There is no such thing for Apple’s JavaScript engine, as far as I know.

I agree with your assessment of Script Debugger. However, in my time I have created intricate multi-departmental workflows in AppleScript purely in Script Editor for some very large corporations. :slight_smile:
But again, Script Debugger is an amazing resource tool!