AppleScript which only runs in specific app window

Hello,

With UI Browser, I created the script below which expands / collapses the list of notebooks in the evernote sidebar. That being said my question is a general one, not evernote specific.

Since the script was created with UI Browser, it is created within a certain ‘window’ (in fact a notebook window), ie a specific notebook called Templates for Letters and Emails.

I would like to generalize the script to work in any evernote window (=notebook).

I am an ignoramus. Please don’t be too technical.

thanks in advance for your time and help

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

-- Use this script as a wrapper for GUI Scripting statements when you are confident that GUI Scripting is available and enabled or that the user knows how to enable it if necessary

activate application "Evernote"
tell application "System Events"
	tell process "Evernote"
		-- insert GUI Scripting statements here:
		
		click UI element 3 of UI element 1 of row 30 of outline 1 of scroll area 1 of group 1 of splitter group 1 of window "Templates for Letters and Emails"
		
	end tell
end tell

Isn’t the name of the window how the AppleScript knows which window you want to interact with? How would the script know which window you want to interact with and what it’s name is?

Maybe if you wanted to interact with the front most Evernote window for example, you could query Evernote for the name of that window and dynamically and substitute that in to your existing code?

1 Like

thanks very much. At least I now know what I want, which is the front end window name.

You might want to try something like

tell application "Evernote"
    click UI element 3 of UI element 1 of row 30 of outline 1 of scroll area 1 of group 1 of splitter group 1 of front window
end tell

front window is in the standard AppleScript dictionary, but I don’t have Evernote so can’t double check easily :slight_smile:

2 Likes

Thank you very much Rosemary ! It is a pleasure and an honor to get a reply from you. You are an excellent host on your videos and look stunning.

I had a minor glitch with your script as per below.

The final script which works perfectly thanks to you is:

activate application "Evernote"
tell application "System Events"
	tell process "Evernote"
		-- insert GUI Scripting statements here:
		
		click UI element 3 of UI element 1 of row 30 of outline 1 of scroll area 1 of group 1 of splitter group 1 of front window
		
	end tell
end tell

Your suggestion is very helpful because it is a recurrent problem when I create scripts with UI Browser

1 Like

I’m glad that helped!