I'm using Evernote more often these days and at the moment I have a number of Word files that I want to upload. I've found that while Evernote will accept Word files (at least the Premium version does) there appears to be a problem carrying out a search of these files in iOS. Evernote will show the Word files that contain the search terms but when you open the files the search terms are not highlighted. This is not the case with PDF files. I thought it would be handy to have a service that would convert the files to PDFs and then upload them. I have a couple of scripts that might help me do this.
The first is one based on that produced recently by Luther Fuller that saves a PDF version of a file to the desktop. I've adapted this to use the Save PDF to Evernote item in the print menu by adding some more GU instructions. Here's the adjusted code:
activate application "Pages"
tell application "System Events"
tell process "Pages"
set frontmost to true
-----------------------
keystroke "p" using {command down}
repeat 20 times -- wait for print sheet to appear
delay 1
set frontmost to true
if exists sheet 1 of window 1 then exit repeat
end repeat
if not (exists sheet 1 of window 1) then error "Pages is not responding. The Print dialog failed to appear."
set frontmost to true
-----------------------
set PDFButton to (first menu button of sheet 1 of window 1)
click PDFButton
click menu item 10 of menu 1 of PDFButton -- PDF to Evernote
end tell
activate application "EvernoteHelper"
tell process "Evernote"
set frontmost to true
-----------------------
repeat 20 times -- wait for the Evernote window to appear
delay 1
set frontmost to true
if exists text field 1 of window 1 then exit repeat
end repeat
if not (exists text field 1 of window 1) then error "Evernote window failed to appear."
set frontmost to true
-----------------------
set value of (text field 1 of window 1) to "RequiredTag"
keystroke "w" using {command down}
end tell
end tell
While I was able to add a tag to the file I couldn't find a way of selecting the Evernote notebook that I wanted to use. There's a drop down menu in the window that opens up in Evernote that I can access the button that opens it, with its name shown in UI Browser, but I couldn't find the name of the fields. Is there a way of doing this?
I came across the following code here to be used as a service with Automator to upload the Word files to Evernote; it doesn't though carry out the conversion to PDF. I wondered if the answer would be to include some code in this to carry out this conversion.
on run {input}
tell application "Evernote"
repeat with SelectedFile in input
try
create note from file SelectedFile notebook "Auto Import"
on error errMessage number errNumber
if the errNumber is equal to 4 then
-- The file being imported is not supported
set userCanceled to false
try
display dialog "Your Evernote account does not support the import of this type of file. Why not consider upgrading?" buttons {"Cancel", "Go Premium"} default button "Cancel" cancel button "Cancel" with icon caution
on error number -128
set userCanceled to true
end try
-- If the user wishes they can be taken to the Evernote premium upgrade page
if userCanceled is false then
tell application "Safari"
activate
end tell
end if
else
-- Unspecified failure
display alert "Import into Evernote failed" message "Error(" & errNumber & "): " & errMessage as warning
end if
end try
end repeat
end tell
end run
Although at the moment I'm just concerned with some Word files ideally I would like to have a service that would carry out the conversion of any type of file to a PDF, uploading this to a notebook in Evernote. I'd be grateful if someone could comment on the best way of achieving this using either of the above or otherwise.
Thanks.
Eric Robertson