AppleScript to enable Typinator when Todoist "Quick Entry" activates?

I'd like Typinator to activate multiple rule sets when Todoist "Quick Entry" dialog window is active.

I am hoping to trigger an AppleScript to detect the dialog window when I press + Space

This is what Winfo.app to detect the dialog winowID:
Screenshot 2022-03-06 at 19.50.09

Thanks to @ccstone for providing links to this useful tool!

My AppleScript knowledge is rather basic, so this is my futile attempt:

tell application "Typinator"
	if windowID of front window is "9667" then set rule set "Todoist.app Projects" to enabled
end tell

This is an example from Typinitor guide to pause expansions:

tell application "Typinator"
	if exists rule set "Scripting" then
		if enabled of rule set "Scripting" then
			expand string "scx"
			pause expansions
		end if
	end if
end tell

Any help strongly appreciated!

Hey there! The way that is written is telling Typinator to look for a Typinator window with that ID number.

I don't have the Todoist app so I am rather limited in how much I can help, but you my first question is how are you triggering the Todoist "Quick Entry" dialog window? I ask because if you're using a hotkey, then you could likely trigger it via AppleScript using system events, and then right after that enable your Typinator set(s).

Report back and we can help further. :grin:

2 Likes

I am using Space to trigger the dialog windows!

Ok then! Try this:

tell application "System Events"
	tell application process "Todoist"
		key code 49 using {control down}
	end tell
end tell

tell application "Typinator"
	set enabled of rule set "Todoist.app Projects" to true
end tell

Basically that uses System Events to simulate that same hotkey combination, sending it to the Todoist app (which theoretically would trigger your dialog window), and then the next section enables your Typinator set.

Let me know if that works for you or not and we can go from there.

Thanks, that works like a charm! Any idea on how to get the Typinator set to deactivate when the dialog window is gone?

Basically I want the abbreviations set to be active only for Todoist.app and for the "Quick Entry" dialog window, which are not considered to be the same thing by KM or the system in general.

Great! To deactivate the Typinator set when the dialog window is gone try the AppleScript below. It should theoretically wait until the window disappears and then disable the set. I can't guarantee it will work because I don't know exactly what kind of window the Todoist dialog window is... but I imagine it will have an AXSystemDialog subrole. Try it out and let me know if it works or not.

--sends shortcut to activate Todoist Quick Entry
tell application "System Events"
	tell application process "Todoist"
		key code 49 using {control down}
	end tell
end tell

--enable Typinator set
tell application "Typinator"
	set enabled of rule set "Todoist.app Projects" to true
end tell

--pause until Todoist Quick Entry window disappears
tell application "System Events"
	tell application process "Todoist"
		repeat until not (exists (first window whose subrole is "AXSystemDialog"))
			delay 0.1
		end repeat
	end tell
end tell

--disable Typinator set
tell application "Typinator"
	set enabled of rule set "Todoist.app Projects" to false
end tell

Looks fantastic, although is not working at the moment.

Here is a UI Browser report on the Todoist "Quick Entry" window:

***PATH:***

application "Todoist"

system dialog "Todoist" (window 1)

***ACTIONS:***

raise

***ATTRIBUTES (long values are truncated to 60 characters):***

activation point

*type:* point

*value:* {1410, 226} x, y

*modifiable:* no

cancel button

*type:* (null)

*value:* (null)

*modifiable:* no

children

*type:* array

*value:* (array of 0 items)

*modifiable:* no

children in navigation order

*type:* array

*value:* (array of 0 items)

*modifiable:* no

close button

*type:* UIElement

*value:* close button

*modifiable:* no

default button

*type:* (null)

*value:* (null)

*modifiable:* no

document

*type:* (null)

*value:* (null)

*modifiable:* no

keyboard focused

*type:* Boolean

*value:* false

*modifiable:* no

frame

*type:* rect

*value:* {{1400, 212}, {640, 668}} x, y, width, height

*modifiable:* no

full screen

*type:* Boolean

*value:* false

*modifiable:* no

full screen button

*type:* (null)

*value:* (null)

*modifiable:* no

grow area

*type:* (null)

*value:* (null)

*modifiable:* no

main

*type:* Boolean

*value:* true

*modifiable:* yes

minimize button

*type:* UIElement

*value:* minimize button

*modifiable:* no

minimized

*type:* Boolean

*value:* false

*modifiable:* no

modal

*type:* Boolean

*value:* false

*modifiable:* no

parent

*type:* UIElement

*value:* application "Todoist"

*modifiable:* no

position

*type:* point

*value:* {1400, 212} x, y

*modifiable:* yes

proxy

*type:* (null)

*value:* (null)

*modifiable:* no

AXReplaceRangeWithText

*type:* (null)

*value:* (null)

*modifiable:* parameterized

role

*type:* string

*value:* AXWindow

*modifiable:* no

type

*type:* string

*value:* "system dialog"

*modifiable:* no

sections

*type:* array

*value:* (array of 0 items)

*modifiable:* yes

size

*type:* size

*value:* {640, 668} width, height

*modifiable:* no

subrole

*type:* string

*value:* system dialog

*modifiable:* no

title

*type:* string

*value:* "Todoist"

*modifiable:* no

title UIelement

*type:* (null)

*value:* (null)

*modifiable:* no

toolbar button

*type:* (null)

*value:* (null)

*modifiable:* no

zoom button

*type:* UIElement

*value:* zoom button

*modifiable:* no

***NOTIFICATIONS:***

announcement requested

created

drawer created

element busy state changed

focused UI element changed

focused window changed

help tag created

layout changed

main window changed

moved

resized

row collapsed

row count changed

row expanded

selected cells changed

selected children changed

selected children moved

selected columns changed

selected rows changed

selected text changed

sheet created

title changed

UI element destroyed

units changed

value changed

window deminiaturized

window miniaturized

window moved

window resized

This is very helpful, I didn’t realize before you had UI Browser otherwise I would have asked you to do something for me from the beginning haha. Replace the third section in the AppleScript with what I have below and try it again. If it still doesn’t work, let me know because UI Browser has a way to get even more information on that window that will tell us very clearly how to interact with it.

--pause until Todoist Quick Entry window disappears
tell application "System Events"
	tell application process "Todoist"
		repeat until not (exists window 1) --THIS LINE HAS BEEN MODIFIED
			delay 0.1
		end repeat
	end tell
end tell

Thanks so much for your help, this macro is sorely needed! The script update didn't seem to help unfortunately :frowning:

This is the overall script as pasted in KM:

Script
--sends shortcut to activate Todoist Quick Entry
tell application "System Events"
	tell application process "Todoist"
		key code 49 using {control down}
	end tell
end tell

--enable Typinator set
tell application "Typinator"
	set enabled of rule set "Todoist.app Projects" to true
end tell

--pause until Todoist Quick Entry window disappears
tell application "System Events"
	tell application process "Todoist"
		repeat until not (exists window 1) --THIS LINE HAS BEEN MODIFIED
			delay 0.1
		end repeat
	end tell
end tell

--disable Typinator set
tell application "Typinator"
	set enabled of rule set "Todoist.app Projects" to false
end tell

I tried extracting the hotkey AppleScript action and make it a KM hotkey action, but it didn't work:

Here are my Typinator settings:

That's because the KM action is not sending the hotkey to Todoist like the AppleScript does. There is a way to do this, but this is not really the problem here.

Do this for me:

1. Open UI Browser and click the Switch to Screen Reader button. (click to expand/collapse screenshot)

Screen Shot 2022-03-08 at 13.08.23

2. The following window will appear showing information about the app underneath your cursor, move your cursor over the Todoist window. (click to expand/collapse screenshot)

3. Hit the hotkey indicated in the red outlined portion (your hotkey may be different than mine) to jump to that portion of the app in UI Browser's main window. (click to expand/collapse screenshot)

4. Right click on the highlighted portion... (click to expand/collapse screenshot)

5. Click Reference to Selected Element... (click to expand/collapse screenshot)

Screen Shot 2022-03-08 at 13.10.15

6. Report back what is shown in this screen, making sure that Index is checked and not Name. (click to expand/collapse screenshot)

Let me know what you find with that and we'll go from there.

There we go:

window "Todoist" 



By the way, extracting the hotkey from the script and making it a KM action successfully calls the dialog window. Is only the text expansion that does not work. Typing in the window is al messed up, huge delay or no input response at all. Which is similar to what happens with the AppleScript alone.

Hmmm... this is odd, but some apps just don't play well with AppleScript.

Try this script below to ensure that AppleScript can actually detect the window...

tell application "System Events"
	tell application process "Todoist"
		
		--sends hotkey shortcut directly to Todoist
		key code 49 using {control down}
		
		--pauses until window appears
		repeat until window 1 exists
			delay 0.1
		end repeat
		
		--displays dialog indicating AppleScript has detected the window
		display dialog ¬
			"Window 1 Exists" buttons {"Continue", "Cancel"} ¬
			default button 1 cancel button 2 ¬
			with title "Testing AppleScript capabilities with Todoist" with icon caution
		
	end tell
end tell

Thanks for sticking around on this one.

Here's the result:

My pleasure! I enjoy troubleshooting things even though I'm not always very good at it. :laughing:

Something very strange is going on... because there's no reason you should be getting multiple display dialogs appearing... see my screen recording to see the same script used with Notes, only one display dialog.

Ok so this has me irritated enough that I downloaded the app to figure out what is going on. :laughing: Try this updated script below and report back. On my system, it works just as I expect it to. The AppleScript runs until the Quick Entry window appears, shows a notification from Control Center (much less disruptive than display dialogs), then waits until that window disappears and shows another notification. Theoretically I could add in the Typinator portions now too, but I want to see if this works on your end before I do that.

Note that for whatever reason Todoist would not allow me to set Space as the hotkey so I set it to a different hotkey for testing: ControlOptionCommandShiftl+ (the plus being the one next to the delete key).

Sreen Recording (click to expand/collapse)

SD and Notes demo

AppleScript (click to expand/collapse)
tell application "System Events"
	tell application process "Todoist"
		
		--sends hotkey shortcut directly to Todoist (using the + symbol next to the delete key)
		key code 24 using {control down, option down, command down, shift down}
		
		--pauses until window appears
		repeat until exists (first window whose subrole is "AXSystemDialog")
			delay 0.1
		end repeat
		
		--display notification that the window appeared
		display notification "Todoist AXSystemDialog Window Exists"
		
		--pauses until window disappears
		repeat until not (exists (first window whose subrole is "AXSystemDialog"))
			delay 0.1
		end repeat
		
		--display notification that the window disappeared
		display notification "Todoist AXSystemDialog Window Does Not Exist"
		
	end tell
end tell

UPDATE: I just added in some Typinator script to enable/disable one of my sets and the AppleScript works great for me. Hopefully it works for you too!

@splitpersonality Hey Alex, were you able to get your macro working?

-Chris

It's working. I can't even explain how grateful I am for your help. I've been wanting to do this for years!

Complete AppleScript:

tell application "System Events"
	tell application process "Todoist"
		
		--pauses until window appears
		repeat until exists (first window whose subrole is "AXSystemDialog")
			delay 0.1
		end repeat
		
		--display notification that the window appeared
		display notification "Todoist AXSystemDialog Window Exists"
		
		--enable Typinator set
		tell application "Typinator"
			set enabled of rule set "Todoist.app Projects" to true
			set enabled of rule set "Todoist.app @Tags" to true
			set enabled of rule set "Todoist.app Text" to true
			set enabled of rule set "Todoist.app Word Sets" to true
		end tell
		
		--pauses until window disappears
		repeat until not (exists (first window whose subrole is "AXSystemDialog"))
			delay 0.1
		end repeat
		
		--disable Typinator set
		tell application "Typinator"
			set enabled of rule set "Todoist.app Projects" to false
			set enabled of rule set "Todoist.app @Tags" to false
			set enabled of rule set "Todoist.app Text" to false
			set enabled of rule set "Todoist.app Word Sets" to false
		end tell
		
		--display notification that the window disappeared
		display notification "Todoist AXSystemDialog Window Does Not Exist"
		
	end tell
end tell

I'll play around with including the other sets, but I am confident they'll work as well.

UPDATE: It all works. I managed to find the exception: it does not work if Typinator editor windows is active.

Glad it appears to be working for the most part and glad to have helped!

Just out of curiosity, what doesn’t work when the Typinator window is active? The video appears to show things when they are working so I just want to make sure i'm not missing something...

My example was just to show that everything is working.

The only exception is if you try to call Todoist "quick entry" window when Typinator settings window is active. In that case Typinator was not active, Finder was.

Hmmm... which part fails exactly? Because the AppleScript is not dependent on which application is or is not frontmost. So the issue might rather be with the way the Todoist window is being activated.

I believe it’s because Typinator sets are not active in Typinator itself. Typinator thinks it’s still active when the Todoist dialog appears, so it does not expand the text.

A workaround could be to tell KM to activate Finder when pressing CTRL+SPACE if Typinator is at the front.

1 Like