Simple way to check if just laptop or another screen is connected?

Hi

i want to put into a variable a 0/1 entry based on wether a laptop is roaming (ie not connected to an external screen) or at home connected to external screens. I can also live with a non variable solution based on if then (taking into account screens connected).
Anyone has suggestions of a quick way to do so?

Perhaps something like this ?

27

JS source

(() => {
    'use strict';

    ObjC.import('AppKit');

    return 1 < ObjC.unwrap($.NSScreen.screens).length ? (
        1
    ) : 0;
})();

Or equivalently, for an Execute Applescript action:

use AppleScript version "2.4"
use framework "Foundation"
use framework "Appkit"
use scripting additions

if 1 < length of (current application's NSScreen's screens as list) then
    1
else
    0
end if

I think you could also branch on the value returned by the KM token %Screen%External%, which will be 0,0,0,0 if no external screen is attached.

Take a look at SCREENCOUNT function.

Use a If Then Else action, like this:

image

1 Like

thx guys. @JMichaelTX thats exactly what i was looking for

thx alot and happy holidays!

Z

1 Like