Embedded Applescript for use with Evernote no longer running

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

I have been using a Hazel rule with an embedded script for quite some time, and things have worked well. I've recently switched computers, upgraded Hazel, etc. and things are no longer working as they should.

The script is part of a rule that takes a file that has been named with the format "FileName|NotebookName|tagName1|tagName2|" and puts it into Evernote, with the file name, notebook, and two tags all lined up. Now, I get nothing (and nothing of value in the log, in debug or otherwise).

I've searched, and came up with a couple of things something that I thought were possibilities,

1.change the line
tell application "Evernote"
to
tell application id "com.evernote.Evernote"

2. change the line
create note from file theFile ...
to
set theNote to create note from file theFile ...

I tried that these each (singly and in combination) and it did not make any difference. Any other things to try?

Code: Select all
tell application "Finder"
   set myTokens to name of theFile -- get the filename which includes the tokens I'm going to use as tags
   try
      set oldDelims to AppleScript's text item delimiters -- save their current state
      set AppleScript's text item delimiters to {"|"} -- declare new delimiters used in filename
      set name of theFile to text item 1 of myTokens & ".PDF" -- contains the name
      set book to text item 2 of myTokens -- contains the notebook
      set tag1 to text item 3 of myTokens -- contains the type
      set tag2 to text item 4 of myTokens -- contains a tag
      tell application "Evernote"
         activate
         create note from file theFile notebook {book} tags {tag1, tag2}
      end tell
      set AppleScript's text item delimiters to oldDelims -- restore them
   on error
      set AppleScript's text item delimiters to oldDelims -- restore them in cases where something went wrong
   end try
end tell
12bruce
 
Posts: 10
Joined: Sun Mar 29, 2015 10:49 am

Have you tried the script outside of Hazel? You might want to print out variables at different points in the script to figure out where things may be going wrong.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I did try to tinker with the applescript editor, but I’m afraid it was a bit of trying to drink from a firehose. Any suggestion on simple steps would be appreciated.
12bruce
 
Posts: 10
Joined: Sun Mar 29, 2015 10:49 am

A bit of further tinkering and finangeling... I seem to have found a way to load the script into applescript editor, provide an input and run the script. This surfaced an error, but not sure how to address "error number -1700 from alias...", which is associated with "Bad parameter data was detected or there was a failure while performing a coercion." (according to developer.apple.com list of error codes).

Any help with this would be greatly appreciated.

Below is the content of "events" from applescript editor, and below that is the actual script in the editor.

Code: Select all
tell application "Script Editor"
   choose file
      --> alias "/Users/bruce/Documents/2212 TEST3|Things|receipt|tool|.pdf"
end tell
tell application "Finder"
   get name of alias "Macintosh HD:Users:bruce:Documents:2212 TEST3|Things|receipt|tool|.pdf"
      --> "2212 TEST3|Things|receipt|tool|.pdf"
   set name of alias "Macintosh HD:Users:bruce:Documents:2212 TEST3|Things|receipt|tool|.pdf" to "2212 TEST3.PDF"
      --> "2212 TEST3.PDF"
end tell
tell application "Evernote"
   activate
   create note from file alias "/Users/bruce/Documents/2212 TEST3|Things|receipt|tool|.pdf" notebook {"Things"} tags {"receipt", "tool"}
      --> error number -1700 from alias "/Users/bruce/Documents/2212 TEST3|Things|receipt|tool|.pdf" to file
end tell
Result:
{""}


Code: Select all
set theFile to choose file

hazelProcessFile(theFile)

on hazelProcessFile(theFile)
   tell application "Finder"
      set myTokens to name of theFile -- get the filename which includes the tokens I'm going to use as tags
      try
         set oldDelims to AppleScript's text item delimiters -- save their current state
         set AppleScript's text item delimiters to {"|"} -- declare new delimiters used in filename
         set name of theFile to text item 1 of myTokens & ".PDF" -- contains the name
         set book to text item 2 of myTokens -- contains the notebook
         set tag1 to text item 3 of myTokens -- contains the type
         set tag2 to text item 4 of myTokens -- contains a tag
         tell application "Evernote"
            activate
            create note from file theFile notebook {book} tags {tag1, tag2}
         end tell
         set AppleScript's text item delimiters to oldDelims -- restore them
      on error
         set AppleScript's text item delimiters to oldDelims -- restore them in cases where something went wrong
      end try
   end tell
   
end hazelProcessFile
12bruce
 
Posts: 10
Joined: Sun Mar 29, 2015 10:49 am

I have run the script again (and now several times) and have now a different listing of events - listing below. I'm guessing the script didn't go down the "try" leg and skipped to the "on error". Not clear to me why no error, and why different from the earlier running.

Code: Select all
tell application "Script Editor"
   choose file
end tell
tell application "Finder"
   get name of alias "Macintosh HD:Users:bruce:Documents:2212 TEST3|Things|receipt|tool|.pdf"
   set name of alias "Macintosh HD:Users:bruce:Documents:2212 TEST3|Things|receipt|tool|.pdf" to "2212 TEST3.PDF"
end tell
Result:
{""}
12bruce
 
Posts: 10
Joined: Sun Mar 29, 2015 10:49 am

OK - problem solved.

There seems to have been a conflict with the use of "name" in the script. I changed the second instance of "name" and the script then loaded the file into evernote. A few more tweaks and it now seems to work (at least in Script Editor)
12bruce
 
Posts: 10
Joined: Sun Mar 29, 2015 10:49 am


Return to Support