How Can I Automate Drag and Drop of File to App Icon in Dock?

###How Can I Automate Drag and Drop of File to App Icon in Dock?

Use Case:

  • I’ve got an HTML file that I want to import into Evernote.
  • The only way Evernote supports this is by drag and drop of the HTML file onto the Evernote icon in the Mac Dock.
  • I have a script which creates the HTML file, and I would like to import into Evernote at the end.

All ideas welcome!

I think it’s easier to use applescript to do the work.

You are absolutely correct.

I thought that creating an EN Note from HTML using AppleScript would NOT pull in the images referenced by the HTML.
But upon testing I just completed, I have found it does.

I’ll post a more complete script later, but for those that are interested, here is my test script:

###Test AppleScript

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

--- GET THE HTML FILE YOU WANT TO READ ---
set pathInputFile to (choose file with prompt "Select the HTML file")

--- READ THE FILE CONTENTS ---
set htmlStr to read pathInputFile
set noteTitle to "TEST Import HTML by Script"
set nbName to ".InWork"

tell application "Evernote" 
  create note with html htmlStr title noteTitle notebook nbName  
end tell

Hey JM,

You’ve found a solution, but let me answer your original question.

To simulate opening files by dragging and dropping to an app-icon in the Finder:

tell application "Finder"
   set finderSelectionList to selection as alias list
   if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
   
   open finderSelectionList using application file id "com.apple.TextEdit"
   
end tell

And for that matter the open verb is universal in AppleScript, so something like this should generally work even if an app is NOT scriptable:

tell application "Finder"
   set finderSelectionList to selection as alias list
   if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
end tell

tell application "Editra"
   if not running then
      launch
      delay 0.5
   end if
   activate
   open finderSelectionList
end tell

-Chris

4 Likes

Thank you Chris! That works perffectly! :+1:

1 Like

KM has the Open The Finder Selection action which should allow any selected file to be opened by any specified application. Thus, one macro could be used to open any Finder selection with (in this case) Evernote.

2 Likes

Another perfect solution! :+1:

KM continues to amaze me. I’ve used that KM Action many, many times. Yet it never occurred to me to use it in this case, not even after @ccstone’s script.

Thanks for pointing this out, @NaOH.

You guys are also the reason I hang out here so much. So much talent, experience that is always offered in a friendly manner.

2 Likes

Hey @NaOH,

Thanks! I’d forgotten about that one.  :blush:

-Chris