Jump to content
Sign in to follow this  
pendolino

mac (Archived) applescript to open specific notebook

Recommended Posts

i have a notebook called 'dog food' and i would like to create an applescript to open specifically this notebook.

what i would like to happen when this is run is that evernote comes to the front or launches (depending on state) directly onto this notebook.

another level of development would be to bring forward that notebook and then open a new note but most important is to bring up the specified notebook.

thanks.

Share this post


Link to post

You should be able to use the API to search for notes, and one of the search criteria is "notebook". E.g. if you searched for this, it would find all of the notes in your "My Recipes" notebook:

notebook:"My Recipies"

Share this post


Link to post

thanks but what i was looking for was the exact applescript code that i could run on my mac (as a script file or similar) to call a specific notebook and that script would be saved specifically for calling just that notebook.

any hints on the code? im guessing it should not be more than two or three lines.

Share this post


Link to post

It would be simple if Evernote's AppleScript interface was anywhere near complete. As it is, it lacks basic things like the "open" verb, as well as any concept of a document or a window. This makes it useless for a lot of typical things you might want to do.

As someone who has been waiting a long time for several AppleScript bugs to be fixed, I'm not optimistic it will happen anytime soon. More's the pity.

Share this post


Link to post
It would be simple if Evernote's AppleScript interface was anywhere near complete. As it is, it lacks basic things like the "open" verb, as well as any concept of a document or a window. This makes it useless for a lot of typical things you might want to do.

As someone who has been waiting a long time for several AppleScript bugs to be fixed, I'm not optimistic it will happen anytime soon. More's the pity.

roblewis - thank you for confirming my suspicions. the 'open' command was something i was actually looking for in the applescript library and had assumed was implemented under some other name since one would assume this basic function was already somehow part of the library.

my guess, based on this and other observations, is that EN is too busy with multi-platform capabilities to focus on one (mac) system's idiosyncrasies. i'd likely do the same if i was in their place and mac users only represented 10% of the user base.

still i am optimistic and this is a very minor gripe (my bigger one is speed!).

Share this post


Link to post

Pendolino -- thought I'd answer your question from the other thread in this one:

Short answer -- There's no way that I know of to trigger Evernote to open up directly to a notebook.

You can use AppleScript to retrieve the titles of every note in a notebook and create it's own list. Presumably, you could adapt the code in the other thread to allow you to select a note from that list and open up the individual notes that way. Ugly -- but it would work.

Rob Lewis, Pendolino, and other Mac Users

Now that the transition to new CSS-rich notes is almost done (and the Mac team has an additional senior developer on board), I think that this is the time to make your need for AppleScript improvements known.

  • Like 1

Share this post


Link to post

Great news! AppleScript improvements needed:

1. Fix reported bugs.

2. Flesh out the API by adding at least the mandatory Standard Suite of objects and commands, as well as the Text Suite.

3. The Image Suite would be great, particularly as regards handling metadata contained in images stored in EverNote.

4. Support the OpenMeta tagging system (I'm not sure this is specific to AppleScript; it needs to be done for the whole app).

Thanks!

Share this post


Link to post

Hey there!

This command selects a specified notebook in the notebook list of the main window ("collection window") provided it's Evernote's first window (source: https://www.evernote...veloper/mac.php):


set query string of window 1 to "notebook:Articles"

The same method also works for stacks:


set query string of window 1 to "stack:"Private stuff""

The following script fulfills the OP's demands: It makes Evernote come to the front or launch (depending on state) with a specified notebook selected. Please note that this script requires the global "Search in Evernote" keyboard shortcut to be configured in Evernote's preferences (and accordingly set in the script's source code).

Please also note that the notebook/stack selection of existing collection windows might be changed.


set destination to "notebook:Test"

tell application "System Events"
-- Let's make sure Evernote is running. If Evernote needs to be started, wait a sec!
if not (exists process "Evernote") then
tell application "Evernote" to activate
delay (3)
end if
-- Now let's invoke a collection window by starting a global search.
keystroke space using {option down}
delay (0.5)
end tell

-- Sometimes it needs a moment for a collection window to be created.
-- As long as no collection window exists, trying to change its query string will result in an error.
-- We'll simply try again until we succeed.

repeat
set tryagain to true
try
tell application "Evernote"
set query string of window 1 to destination
end tell
set tryagain to false
on error
tell application "System Events"
keystroke space using {option down}
end tell
delay (1)
set tryagain to true
end try
if not tryagain then exit repeat
end repeat

If you don't want to rely on the global search hotkey, things get kind of tricky. I particularly found the following tasks rather difficult:

  • Make an existing collection window frontmost among a number of other Evernote windows (You can tell most applications to "set frontmost of window X to true" or to "set index of window X to 1". But Evernote [Version 3.0.4 (206275)] doesn't know the frontmost property for windows and for some reason returns an error when you try to change a window's index.)
  • Set the collection window active (meaning: put the input focus on it) without bringing any other non-minimized Evernote window to the front.

Here's the alternatives I came up with:

  1. Skimming through all Evernote windows, then bringing all non-minimized Evernote windows to the front with a collection window on top and activated.
  2. Skimming through all Evernote windows, then activating only the collection window by simulating mouseclicks on Evernote's dock icon. This method may be a little bit slower than (1).
  3. Invoking a collection window by simulating mouseclicks on Evernote's menu bar icon and the "Search in Evernote" entry, then changing the query string of the collection window. (Obviously this requires the menu bar item to be present).

I wish I knew of a more elegant way to bring only the collection window to the front. Any suggestions are welcome! Anyways, here are scripts for alternative methods (1) and (2). Please note that -- just like before -- the notebook/stack selection of existing collection windows might be changed.


(* (1) Skimming through all Evernote windows, then bringing all non-minimized Evernote windows to the front with a collection window on top and activated. *)

set destination to "notebook:Articles"
set collectionWindowTitle to "not available"

tell application "System Events"
if not (exists process "Evernote") then
tell application "Evernote" to activate
delay (3)
end if
end tell

tell application "Evernote"

repeat with ew in every window
if class of ew is collection window then
set collectionWindowTitle to name of ew
exit repeat
end if
end repeat

if collectionWindowTitle is "not available" then
open collection window with query string destination
tell application "System Events"
set frontmost of process "Evernote" to true
end tell
else
tell application "System Events"
tell process "Evernote"
perform action "AXRaise" of window collectionWindowTitle
end tell
set frontmost of process "Evernote" to true
end tell
set query string of window collectionWindowTitle to destination
end if

end tell


(* (2) Skimming through all Evernote windows, then activating only the collection window by simulating mouseclicks on the Dock icon. I think this method may be a little bit slower than (1).

Note: This script is just the same as the script for alternative method (1), except for the last 'tell'-block. *)

set destination to "notebook:Gedächtnis"
set collectionWindowTitle to "not available"

tell application "System Events"
if not (exists process "Evernote") then
tell application "Evernote" to activate
delay (3)
end if
end tell

tell application "Evernote"

repeat with ew in every window
if class of ew is collection window then
set collectionWindowTitle to name of ew
exit repeat
end if
end repeat

if collectionWindowTitle is "not available" then
open collection window with query string destination
tell application "System Events"
set frontmost of process "Evernote" to true
end tell
else
tell application "System Events" to tell process "Dock"
tell UI element "Evernote" of list 1
perform action "AXShowMenu"
click menu item collectionWindowTitle of menu 1
end tell
end tell
set query string of window collectionWindowTitle to destination
end if

end tell

For my own use, I'd like to have icons in my dock that let me switch to specific stacks -- however, existing main windows focussing on different stacks (or notebooks) should not be affected. So if no collection window focusssing on the desired stack (or a notebook within that stack) exists, a new collection window should be opened. I'm going to modify one of above scripts, save it as an application and put it in my dock. Evaluating the note id property of existing collection windows seems to be the way to go... I'll see when I find time for this...

Oh, last but not least, all code gets much shorter if you simply want to open a specific note with known URL in the collection window with Evernote selecting its parent notebook at the same time (provided the location doesn' t change). Simply copy the note link and paste it in this script:

do shell script "open evernote:///view/2378xx8/sx9/c974xxef-3x2c-4exx-xcdf-1ba50d8xxx19/cxx49xxf-3xxc-4ex4-xcdf-1xxx0d827019/"
tell application "Evernote"
set query string of window 1 to "notebook:"Daily Inbox""
end tell

In the last two script, the code got lengthy because we had to manually take care of cases where no collection window existed before we could navigate to a desired location. When opening a specific note via OSX's command "open", however, a collection window is automatically created if none exists.

  • Like 1

Share this post


Link to post
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...