Friday, November 22, 2024

macos – Unable to jot down textual content into Notes.app utilizing AppleScript

I’m attempting to jot down into Notes.app utilizing AppleScript and System Occasions. I’ve the next easy script:

on check(notesAccount, notesFolder, notesName)
    
    inform software "Notes"
        activate
        delay 1.0
        inform account notesAccount
            delay 1.0
            make new notice at folder notesFolder with properties {identify:notesName}
            delay 1.0
            inform software "System Occasions"
                delay 1.0
                inform course of "Notes"
                    delay 1.0
                    keystroke "Hey World"
                finish inform
            finish inform
        finish inform
    finish inform
    
finish check

check("iCloud", "Notes", "Check")

Once I run this script, the notice will get created with the suitable identify, however no textual content is inserted. I do get a “beep” sound, presumably, a sign of an error. I’m presently operating Sequoia 15.1. Accessibility is enabled for Script Editor.

I understand that there are various strategies of writing textual content right into a notice. Nonetheless, for different causes, I want to make use of System Occasions.

Any assist can be vastly appreciated.

UPDATE:

I used to be unable to get the “key code” methodology (see reply beneath) to work. Nonetheless, I used to be in a position to get the “Open Notice in New Window” to work!
Here’s a answer that works primarily based upon red_menace‘s reply:

    on check(notesAccount, notesFolder, notesName)
    
    inform software "Notes"
        activate
        delay 1.0
        inform account notesAccount
            delay 1.0
            present (make new notice at folder notesFolder with properties {identify:notesName})
            delay 1.0
            inform software "System Occasions" to inform course of "Notes"
                click on menu merchandise "Open Notice in New Window" of menu 1 of menu bar merchandise "Window" of menu bar 1
                delay 1.0
                keystroke "Hey World!"
                delay 1.0
                inform software "Notes" to whether it is operating then shut its entrance window
            finish inform
        finish inform
    finish inform
    
finish check

check("iCloud", "Notes", "Check")

I might have most well-liked the “key code” methodology as a result of it is visually cleaner, however this works nicely and I’m completely satisfied! Thanks red_menace!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles