Jump to content
Scooter

AppleScript Type in note

Recommended Posts

I used to have an applescript that worked well for me.  It would create a note and named it based on the date, then place the cursor at the first space and TYPE (not paste, type) a brief word.  The reason the typing is important is the word typed was a textexpander trigger word.  This has worked great for years but it no longer does.  Here is the part that no longer seems to be working.

tell application "Evernote"
    activate
    tell application "System Events"
        keystroke return
        keystroke "..journal "
        keystroke return
        keystroke " "
    end tell
end tell


This used to call up the front note (created above) go into the note then type keystrokes using System Events.  It no longer does that.  it still seems to type the letters, but it's somewhere is space, not the note.  It does trigger textexpander, but even then it's not in the note so it doesn't matter.  Any idea on what has changed and how to fix this?

Share this post


Link to post
10 minutes ago, Scooter said:

The reason the typing is important is the word typed was a textexpander trigger word.  This has worked great for years but it no longer does.

Using AppleScript UI events can be unreliable.

You might want to take a look at expanding the TE snippet into an AppleScript variable, and then pasting that.

See the TextExpander Scripting Dictionary (File > Open Dictionary in Script Editor)

Quote

expandv : Expand snippet as if its abbreviation had been typed, specify either the snippet or its abbreviation.

expand

[snippet snippet] : The snippet to expand.

[abbreviation text] : The abbreviation to expand.

→ boolean : Did a snippet expand

 

Share this post


Link to post
53 minutes ago, JMichaelTX said:

You might want to take a look at expanding the TE snippet into an AppleScript variable, and then pasting that.

Actually, since you are creating a new note, it would be better to just set the Note contents to the TE snippet in the Create Note command.

Share this post


Link to post

Well, the TE isn't just a string, it's  kind of a script with some selections.  To work as it used to, I need to actually trigger and use Textexpander.  Right now I'm working on running the whole process manually though applescript, then sending the results back to applescript.  It's not working yet, and if I do get it working it will be clunky.  I wish the old way still worked.  It was perfect for a long time.

Share this post


Link to post
1 hour ago, Scooter said:

I wish the old way still worked.  It was perfect for a long time.

But it doesn't work now.  Could be due to changes in Evernote, TextExpander, and/or Mac OS.  This makes it very hard to diagnose and fix.

Unless you need to do this many times a day, the best solution now might be to manually type in the TE abbreviation after AppleScript has finished creating the note.  As you know the TE abbreviation can be anything you want.  So, if it was me, I'd made it ";je"  (for journal entry), and be done with it.  Typing 3 chars is not a lot of burden.  Figuring out the problem with the AppleScript could take many hours.  Your choice.

Share this post


Link to post

Actually, I got it working.  A little more awkward than before, but not much.  If anybody is interested and has the same stuff I have, here's what I did: I've moved all my scripts over to Keyboard Maestro, then put a "Move mouse and click here" commend from keyboard maestro, then back to the Applescript to run the rest.  I did upgrade my script to your TE expansion suggestion (actually, it didn't work as expected, but I added expand abbreviation and it worked).  So I'm back up and running.  Thanks for the help.

Share this post


Link to post
1 hour ago, Scooter said:

I've moved all my scripts over to Keyboard Maestro

I'm glad to hear you have solved your problem.  It would be great if you could post your KM macro either here, or in the KM forum.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...