<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Abhishek Sharma</title>
    <description>The latest articles on Forem by Abhishek Sharma (@abhsss96).</description>
    <link>https://forem.com/abhsss96</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1784705%2F8f43ad70-bb4b-43ad-b27f-0083acfcfee7.jpg</url>
      <title>Forem: Abhishek Sharma</title>
      <link>https://forem.com/abhsss96</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abhsss96"/>
    <language>en</language>
    <item>
      <title>Switch Your Samsung M8 Monitor HDMI Inputs from the Terminal (No Remote Needed)</title>
      <dc:creator>Abhishek Sharma</dc:creator>
      <pubDate>Fri, 17 Apr 2026 05:28:05 +0000</pubDate>
      <link>https://forem.com/abhsss96/switch-your-samsung-m8-monitor-hdmi-inputs-from-the-terminal-no-remote-needed-4i84</link>
      <guid>https://forem.com/abhsss96/switch-your-samsung-m8-monitor-hdmi-inputs-from-the-terminal-no-remote-needed-4i84</guid>
      <description>&lt;p&gt;If you run two machines — a work laptop and a personal desktop — connected to a Samsung M8, you already know the pain: reach for the remote, navigate the OSD menu, switch source, repeat twenty times a day. Here's how to collapse that into a single terminal command using the &lt;strong&gt;SmartThings CLI&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The best part: this approach works identically on both &lt;strong&gt;macOS and Linux&lt;/strong&gt; since it's Node.js-based.&lt;/p&gt;




&lt;h2&gt;
  
  
  How This Works
&lt;/h2&gt;

&lt;p&gt;The Samsung M8 is a SmartThings-connected display. Samsung exposes a first-party CLI — &lt;code&gt;@smartthings/cli&lt;/code&gt; — that can send commands to any registered SmartThings device, including input source switching on the M8. No hacking, no reverse engineering, no X11 tools.&lt;/p&gt;




&lt;h2&gt;
  
  
  What You Need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Samsung M8 monitor connected to your SmartThings account&lt;/li&gt;
&lt;li&gt;Node.js (we'll use &lt;code&gt;asdf&lt;/code&gt; for version management)&lt;/li&gt;
&lt;li&gt;SmartThings CLI installed globally via npm&lt;/li&gt;
&lt;li&gt;Your M8's SmartThings device ID&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 1: Install Node.js via asdf
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;asdf&lt;/code&gt; works the same on macOS and Linux, which is why it's the cleanest approach here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;macOS:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;asdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Linux (Ubuntu/Debian):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;curl git
git clone https://github.com/asdf-vm/asdf.git ~/.asdf &lt;span class="nt"&gt;--branch&lt;/span&gt; v0.14.0
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'. "$HOME/.asdf/asdf.sh"'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.zshrc
&lt;span class="nb"&gt;source&lt;/span&gt; ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then install Node.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;asdf plugin add nodejs
asdf &lt;span class="nb"&gt;install &lt;/span&gt;nodejs 24.13.0
asdf global nodejs 24.13.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;--version&lt;/span&gt;   &lt;span class="c"&gt;# v24.13.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 2: Install the SmartThings CLI
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; @smartthings/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;smartthings &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 3: Authenticate with SmartThings
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;smartthings devices
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will open a browser and ask you to log in with your Samsung account. After authentication, it lists all your SmartThings devices.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4: Find Your M8 Device ID
&lt;/h2&gt;

&lt;p&gt;After authentication, &lt;code&gt;smartthings devices&lt;/code&gt; outputs a table. Find your Samsung M8 and copy its device ID — it looks like a UUID:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌────┬─────────────────┬──────────────────────────────────────┐
│ #  │ Label           │ Device ID                            │
├────┼─────────────────┼──────────────────────────────────────┤
│  1 │ Samsung M8      │ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx │
└────┴─────────────────┴──────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Export it in your &lt;code&gt;~/.zshrc.local&lt;/code&gt; (keep it out of your dotfiles repo since it's device-specific):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;SMARTTHINGS_MONITOR_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 5: The Toggle Script
&lt;/h2&gt;

&lt;p&gt;Create &lt;code&gt;~/dotfiles/scripts/monitor_input.sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="c"&gt;# Control Samsung M8 monitor input via SmartThings CLI&lt;/span&gt;
&lt;span class="c"&gt;# Requires: smartthings CLI + SMARTTHINGS_MONITOR_ID env var set in ~/.zshrc.local&lt;/span&gt;

_smartthings_cmd&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;st_bin&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.asdf/installs/nodejs/24.13.0/bin/smartthings"&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$st_bin&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$st_bin&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;command &lt;/span&gt;smartthings &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

_monitor_check&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; _smartthings_cmd &lt;span class="nt"&gt;--version&lt;/span&gt; &amp;amp;&amp;gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"smartthings CLI not found."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Run: npm install -g @smartthings/cli"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="k"&gt;fi
  if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SMARTTHINGS_MONITOR_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"SMARTTHINGS_MONITOR_ID is not set."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Run: smartthings devices   → find your M8 device ID"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Then add to ~/.zshrc.local:  export SMARTTHINGS_MONITOR_ID='&amp;lt;id&amp;gt;'"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

monitor_hdmi1&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  _monitor_check &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Switching to HDMI 1..."&lt;/span&gt;
  _smartthings_cmd devices:commands &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SMARTTHINGS_MONITOR_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="s1"&gt;'main:mediaInputSource:setInputSource("HDMI1")'&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

monitor_hdmi2&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  _monitor_check &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Switching to HDMI 2..."&lt;/span&gt;
  _smartthings_cmd devices:commands &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SMARTTHINGS_MONITOR_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="s1"&gt;'main:mediaInputSource:setInputSource("HDMI2")'&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

monitor_toggle&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  _monitor_check &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="nb"&gt;local &lt;/span&gt;current
  &lt;span class="nv"&gt;current&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;_smartthings_cmd devices:status &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SMARTTHINGS_MONITOR_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; 2&amp;gt;/dev/null &lt;span class="se"&gt;\&lt;/span&gt;
    | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.components.main."samsungvd.mediaInputSource".inputSource.value // empty'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$current&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Could not read current input source."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="k"&gt;fi

  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Current input: &lt;/span&gt;&lt;span class="nv"&gt;$current&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$current&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"HDMI1"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;monitor_hdmi2
  &lt;span class="k"&gt;else
    &lt;/span&gt;monitor_hdmi1
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# Allow running directly: ./monitor_input.sh [hdmi1|hdmi2|toggle]&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;:-}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in
  &lt;/span&gt;hdmi1&lt;span class="p"&gt;)&lt;/span&gt;  monitor_hdmi1 &lt;span class="p"&gt;;;&lt;/span&gt;
  hdmi2&lt;span class="p"&gt;)&lt;/span&gt;  monitor_hdmi2 &lt;span class="p"&gt;;;&lt;/span&gt;
  toggle&lt;span class="p"&gt;)&lt;/span&gt; monitor_toggle &lt;span class="p"&gt;;;&lt;/span&gt;
  &lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Usage: &lt;/span&gt;&lt;span class="nv"&gt;$0&lt;/span&gt;&lt;span class="s2"&gt; [hdmi1|hdmi2|toggle]"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"  or source this file and call monitor_hdmi1 / monitor_hdmi2 / monitor_toggle"&lt;/span&gt;
    &lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="k"&gt;esac&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A couple of things worth noting in &lt;code&gt;_smartthings_cmd&lt;/code&gt;: it tries the asdf-managed binary path first, then falls back to whatever &lt;code&gt;smartthings&lt;/code&gt; is on &lt;code&gt;$PATH&lt;/code&gt;. This means the script works whether you're using asdf or a global npm install.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 6: Wire Up the Aliases
&lt;/h2&gt;

&lt;p&gt;Create &lt;code&gt;~/dotfiles/zsh/aliases/monitor.sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# ── Samsung M8 Monitor Input (SmartThings) ──────────────────────────────────&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; smartthings &amp;amp;&amp;gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nb"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/dotfiles/scripts/monitor_input.sh"&lt;/span&gt; 2&amp;gt;/dev/null

  &lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;hdmi1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'monitor_hdmi1'&lt;/span&gt;
  &lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;hdmi2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'monitor_hdmi2'&lt;/span&gt;
  &lt;span class="nb"&gt;alias &lt;/span&gt;hdmi-toggle&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'monitor_toggle'&lt;/span&gt;
  &lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'monitor_toggle'&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Source it from your &lt;code&gt;.zshrc&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/dotfiles/zsh/aliases/monitor.sh"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;command -v smartthings&lt;/code&gt; guard means the aliases are silently skipped on any machine that doesn't have the CLI installed — no errors, no noise.&lt;/p&gt;




&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hdmi1         &lt;span class="c"&gt;# switch to HDMI 1 (machine A)&lt;/span&gt;
hdmi2         &lt;span class="c"&gt;# switch to HDMI 2 (machine B)&lt;/span&gt;
hdmi-toggle   &lt;span class="c"&gt;# toggle between whichever is active&lt;/span&gt;
t             &lt;span class="c"&gt;# same as hdmi-toggle, just shorter&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it directly without sourcing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~/dotfiles/scripts/monitor_input.sh toggle
~/dotfiles/scripts/monitor_input.sh hdmi1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Workflow in Practice
&lt;/h2&gt;

&lt;p&gt;My setup: work MacBook on HDMI 1, personal Linux desktop on HDMI 2. A single &lt;code&gt;t&lt;/code&gt; in the terminal and the monitor switches — no remote, no OSD, no context switch. Since it goes through SmartThings rather than DDC/CI, it works over the network too, so you don't even need to be in the same session as the machine you're switching away from.&lt;/p&gt;




&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;smartthings CLI not found&lt;/code&gt;&lt;/strong&gt; — Make sure the npm global bin is on your &lt;code&gt;$PATH&lt;/code&gt;. Check with &lt;code&gt;npm bin -g&lt;/code&gt; and add it to your shell profile if missing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;SMARTTHINGS_MONITOR_ID is not set&lt;/code&gt;&lt;/strong&gt; — Add the export to &lt;code&gt;~/.zshrc.local&lt;/code&gt; (not your dotfiles repo) and re-source your shell.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;Could not read current input source&lt;/code&gt;&lt;/strong&gt; — Run &lt;code&gt;smartthings devices:status $SMARTTHINGS_MONITOR_ID&lt;/code&gt; manually to inspect the raw JSON. The capability key may differ slightly on older M8 firmware; look for &lt;code&gt;mediaInputSource&lt;/code&gt; in the output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Commands time out&lt;/strong&gt; — The M8 needs to be on and connected to your Wi-Fi network. Wake it from standby first, or disable deep sleep in the monitor's power settings.&lt;/p&gt;




&lt;p&gt;That's it. SmartThings CLI, one script, four aliases, zero remote-reaching.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Full script and aliases live in my dotfiles: &lt;a href="https://github.com/abhsss96/dotfiles" rel="noopener noreferrer"&gt;github.com/abhsss96/dotfiles&lt;/a&gt; — see &lt;code&gt;scripts/monitor_input.sh&lt;/code&gt; and &lt;code&gt;zsh/aliases/monitor.sh&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>productivity</category>
      <category>terminal</category>
      <category>tooling</category>
    </item>
    <item>
      <title>Switch Your Samsung M8 Monitor Inputs from the Terminal (No Remote Needed)</title>
      <dc:creator>Abhishek Sharma</dc:creator>
      <pubDate>Fri, 17 Apr 2026 05:22:37 +0000</pubDate>
      <link>https://forem.com/abhsss96/switch-your-samsung-m8-monitor-inputs-from-the-terminal-no-remote-needed-48lk</link>
      <guid>https://forem.com/abhsss96/switch-your-samsung-m8-monitor-inputs-from-the-terminal-no-remote-needed-48lk</guid>
      <description>&lt;p&gt;If you run two machines — a work laptop and a personal desktop — connected to a Samsung M8, you already know the pain: reach for the remote, navigate the OSD menu, switch source, repeat twenty times a day. Here's how to collapse that into a single terminal command using the &lt;strong&gt;SmartThings CLI&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The best part: this approach works identically on both &lt;strong&gt;macOS and Linux&lt;/strong&gt; since it's Node.js-based.&lt;/p&gt;




&lt;h2&gt;
  
  
  How This Works
&lt;/h2&gt;

&lt;p&gt;The Samsung M8 is a SmartThings-connected display. Samsung exposes a first-party CLI — &lt;code&gt;@smartthings/cli&lt;/code&gt; — that can send commands to any registered SmartThings device, including input source switching on the M8. No hacking, no reverse engineering, no X11 tools.&lt;/p&gt;




&lt;h2&gt;
  
  
  What You Need
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Samsung M8 monitor connected to your SmartThings account&lt;/li&gt;
&lt;li&gt;Node.js (we'll use &lt;code&gt;asdf&lt;/code&gt; for version management)&lt;/li&gt;
&lt;li&gt;SmartThings CLI installed globally via npm&lt;/li&gt;
&lt;li&gt;Your M8's SmartThings device ID&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 1: Install Node.js via asdf
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;asdf&lt;/code&gt; works the same on macOS and Linux, which is why it's the cleanest approach here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;macOS:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew &lt;span class="nb"&gt;install &lt;/span&gt;asdf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Linux (Ubuntu/Debian):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;curl git
git clone https://github.com/asdf-vm/asdf.git ~/.asdf &lt;span class="nt"&gt;--branch&lt;/span&gt; v0.14.0
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'. "$HOME/.asdf/asdf.sh"'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.zshrc
&lt;span class="nb"&gt;source&lt;/span&gt; ~/.zshrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then install Node.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;asdf plugin add nodejs
asdf &lt;span class="nb"&gt;install &lt;/span&gt;nodejs 24.13.0
asdf global nodejs 24.13.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;--version&lt;/span&gt;   &lt;span class="c"&gt;# v24.13.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 2: Install the SmartThings CLI
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; @smartthings/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;smartthings &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 3: Authenticate with SmartThings
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;smartthings devices
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will open a browser and ask you to log in with your Samsung account. After authentication, it lists all your SmartThings devices.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4: Find Your M8 Device ID
&lt;/h2&gt;

&lt;p&gt;After authentication, &lt;code&gt;smartthings devices&lt;/code&gt; outputs a table. Find your Samsung M8 and copy its device ID — it looks like a UUID:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌────┬─────────────────┬──────────────────────────────────────┐
│ #  │ Label           │ Device ID                            │
├────┼─────────────────┼──────────────────────────────────────┤
│  1 │ Samsung M8      │ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx │
└────┴─────────────────┴──────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Export it in your &lt;code&gt;~/.zshrc.local&lt;/code&gt; (keep it out of your dotfiles repo since it's device-specific):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;SMARTTHINGS_MONITOR_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 5: The Toggle Script
&lt;/h2&gt;

&lt;p&gt;Create &lt;code&gt;~/dotfiles/scripts/monitor_input.sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="c"&gt;# Control Samsung M8 monitor input via SmartThings CLI&lt;/span&gt;
&lt;span class="c"&gt;# Requires: smartthings CLI + SMARTTHINGS_MONITOR_ID env var set in ~/.zshrc.local&lt;/span&gt;

_smartthings_cmd&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;st_bin&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.asdf/installs/nodejs/24.13.0/bin/smartthings"&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$st_bin&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$st_bin&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;command &lt;/span&gt;smartthings &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

_monitor_check&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; _smartthings_cmd &lt;span class="nt"&gt;--version&lt;/span&gt; &amp;amp;&amp;gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"smartthings CLI not found."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Run: npm install -g @smartthings/cli"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="k"&gt;fi
  if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SMARTTHINGS_MONITOR_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"SMARTTHINGS_MONITOR_ID is not set."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Run: smartthings devices   → find your M8 device ID"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Then add to ~/.zshrc.local:  export SMARTTHINGS_MONITOR_ID='&amp;lt;id&amp;gt;'"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

monitor_hdmi1&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  _monitor_check &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Switching to HDMI 1..."&lt;/span&gt;
  _smartthings_cmd devices:commands &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SMARTTHINGS_MONITOR_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="s1"&gt;'main:mediaInputSource:setInputSource("HDMI1")'&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

monitor_hdmi2&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  _monitor_check &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Switching to HDMI 2..."&lt;/span&gt;
  _smartthings_cmd devices:commands &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SMARTTHINGS_MONITOR_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="s1"&gt;'main:mediaInputSource:setInputSource("HDMI2")'&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

monitor_toggle&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  _monitor_check &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="nb"&gt;local &lt;/span&gt;current
  &lt;span class="nv"&gt;current&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;_smartthings_cmd devices:status &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$SMARTTHINGS_MONITOR_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; 2&amp;gt;/dev/null &lt;span class="se"&gt;\&lt;/span&gt;
    | jq &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="s1"&gt;'.components.main."samsungvd.mediaInputSource".inputSource.value // empty'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$current&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Could not read current input source."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&amp;amp;2
    &lt;span class="k"&gt;return &lt;/span&gt;1
  &lt;span class="k"&gt;fi

  &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Current input: &lt;/span&gt;&lt;span class="nv"&gt;$current&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$current&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"HDMI1"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;monitor_hdmi2
  &lt;span class="k"&gt;else
    &lt;/span&gt;monitor_hdmi1
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# Allow running directly: ./monitor_input.sh [hdmi1|hdmi2|toggle]&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;&lt;span class="k"&gt;:-}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in
  &lt;/span&gt;hdmi1&lt;span class="p"&gt;)&lt;/span&gt;  monitor_hdmi1 &lt;span class="p"&gt;;;&lt;/span&gt;
  hdmi2&lt;span class="p"&gt;)&lt;/span&gt;  monitor_hdmi2 &lt;span class="p"&gt;;;&lt;/span&gt;
  toggle&lt;span class="p"&gt;)&lt;/span&gt; monitor_toggle &lt;span class="p"&gt;;;&lt;/span&gt;
  &lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Usage: &lt;/span&gt;&lt;span class="nv"&gt;$0&lt;/span&gt;&lt;span class="s2"&gt; [hdmi1|hdmi2|toggle]"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"  or source this file and call monitor_hdmi1 / monitor_hdmi2 / monitor_toggle"&lt;/span&gt;
    &lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="k"&gt;esac&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A couple of things worth noting in &lt;code&gt;_smartthings_cmd&lt;/code&gt;: it tries the asdf-managed binary path first, then falls back to whatever &lt;code&gt;smartthings&lt;/code&gt; is on &lt;code&gt;$PATH&lt;/code&gt;. This means the script works whether you're using asdf or a global npm install.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 6: Wire Up the Aliases
&lt;/h2&gt;

&lt;p&gt;Create &lt;code&gt;~/dotfiles/zsh/aliases/monitor.sh&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# ── Samsung M8 Monitor Input (SmartThings) ──────────────────────────────────&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; smartthings &amp;amp;&amp;gt;/dev/null&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
  &lt;/span&gt;&lt;span class="nb"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/dotfiles/scripts/monitor_input.sh"&lt;/span&gt; 2&amp;gt;/dev/null

  &lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;hdmi1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'monitor_hdmi1'&lt;/span&gt;
  &lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;hdmi2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'monitor_hdmi2'&lt;/span&gt;
  &lt;span class="nb"&gt;alias &lt;/span&gt;hdmi-toggle&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'monitor_toggle'&lt;/span&gt;
  &lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;t&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'monitor_toggle'&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Source it from your &lt;code&gt;.zshrc&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/dotfiles/zsh/aliases/monitor.sh"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;command -v smartthings&lt;/code&gt; guard means the aliases are silently skipped on any machine that doesn't have the CLI installed — no errors, no noise.&lt;/p&gt;




&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hdmi1         &lt;span class="c"&gt;# switch to HDMI 1 (machine A)&lt;/span&gt;
hdmi2         &lt;span class="c"&gt;# switch to HDMI 2 (machine B)&lt;/span&gt;
hdmi-toggle   &lt;span class="c"&gt;# toggle between whichever is active&lt;/span&gt;
t             &lt;span class="c"&gt;# same as hdmi-toggle, just shorter&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it directly without sourcing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;~/dotfiles/scripts/monitor_input.sh toggle
~/dotfiles/scripts/monitor_input.sh hdmi1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Workflow in Practice
&lt;/h2&gt;

&lt;p&gt;My setup: work MacBook on HDMI 1, personal Linux desktop on HDMI 2. A single &lt;code&gt;t&lt;/code&gt; in the terminal and the monitor switches — no remote, no OSD, no context switch. Since it goes through SmartThings rather than DDC/CI, it works over the network too, so you don't even need to be in the same session as the machine you're switching away from.&lt;/p&gt;




&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;smartthings CLI not found&lt;/code&gt;&lt;/strong&gt; — Make sure the npm global bin is on your &lt;code&gt;$PATH&lt;/code&gt;. Check with &lt;code&gt;npm bin -g&lt;/code&gt; and add it to your shell profile if missing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;SMARTTHINGS_MONITOR_ID is not set&lt;/code&gt;&lt;/strong&gt; — Add the export to &lt;code&gt;~/.zshrc.local&lt;/code&gt; (not your dotfiles repo) and re-source your shell.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;Could not read current input source&lt;/code&gt;&lt;/strong&gt; — Run &lt;code&gt;smartthings devices:status $SMARTTHINGS_MONITOR_ID&lt;/code&gt; manually to inspect the raw JSON. The capability key may differ slightly on older M8 firmware; look for &lt;code&gt;mediaInputSource&lt;/code&gt; in the output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Commands time out&lt;/strong&gt; — The M8 needs to be on and connected to your Wi-Fi network. Wake it from standby first, or disable deep sleep in the monitor's power settings.&lt;/p&gt;




&lt;p&gt;That's it. SmartThings CLI, one script, four aliases, zero remote-reaching.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Full script and aliases live in my dotfiles: &lt;a href="https://github.com/abhsss96/dotfiles" rel="noopener noreferrer"&gt;github.com/abhsss96/dotfiles&lt;/a&gt; — see &lt;code&gt;scripts/monitor_input.sh&lt;/code&gt; and &lt;code&gt;zsh/aliases/monitor.sh&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>productivity</category>
      <category>terminal</category>
      <category>mac</category>
    </item>
  </channel>
</rss>
