Can you use the return value from a tell statement in an if-comparison?

This code returns an integer

tell application "Google Chrome" to count tabs of front window

can you somehow use that - as a oneliner, without temporary variables - in an if-statement? Something like

if ((tell application "Google Chrome" to count tabs of front window ) = 1) then

?

Try this (not tested):

if (count tabs of front window of application "Google Chrome" ) is 1 then 
-- do your thing
end if

It compiles but fails:

error "Google Chrome got an error: Can’t make |tabs| of window 1 into type specifier." number -1700 from |tabs| of window 1 to specifier

Any ideas?

count windows of application "Google Chrome"

works!?

Tell to IF:

 

tell application "Safari" to if (count tabs of front window) = 1 then say "Hello"

 

2 Likes

ChatGPT suggested

tell application "Google Chrome" to tell front window to if (count tabs) = 2 then

Seems to work.

This is the same as what I suggested. Written by a robot in a different form.

It might be that snippets without the required tells are failing.