This article introduces a method to automatically copy SMS verification codes received from Android to the Windows 10 clipboard using the Ruby programming language.

Introduction
Entering 2FA codes is tedious, but with this program, you can automatically copy SMS verification codes from your Android device to the Windows 10 clipboard.
Now, let’s look at the procedure.
Overall Flow
Implementing this program is not difficult, but it may take time because it requires combining several technologies. However, once implemented, you can apply this to manipulate other Android data.
- When you receive an SMS on your Android device, use IFTTT to make a web request with JSON data.
- A Sinatra server on Ubuntu receives this data, parses and filters it, and saves the text to a file.
- Copy the data from the text file to the clipboard via WSL (Windows Subsystem for Linux).
Preparation
The following preparations are necessary.
- Use a WiFi router that supports port forwarding. This allows you to request from a global IP public URL to a server running locally.
- Set up WSL (Windows Subsystem for Linux). This is a tool with benefits for Linux and programming beginners.
I’ve been using WSL from the beginning, so I’ll explain the benefits of WSL for Linux and programming beginners WSL bash on ubuntu on windows installation procedure
- Set up the Ruby environment. This is necessary to run Sinatra.
sudo apt update
sudo apt install build-essential patch zlib1g-dev liblzma-dev ruby{,-dev} -y
sudo gem install bundler
mkdir -p /mnt/c/pg/ruby_dev && cd $_
sudo bundle init
vim Gemfile
sudo bundle install
Gemfile contents:
gem "pry"
gem "sinatra"
Procedure
Now, let’s look at the specific procedure.
- Set up port forwarding on your WiFi router.

-
Create an applet in IFTTT.
- Event: “Any new SMS received”
- Action: “Webhooks”
- Title (example): “If Any new SMS received, then post to WSL”
- URL (example): “http://[Your_IP]:8005/androidsms”
- HTTP Method: “POST”
- Content Type: “JSON”
- Body:
{"ContactName": "{{ContactName}}", "Text": "{{Text}}", "OccurredAt": "{{OccurredAt}}", "FromNumber": "{{FromNumber}}"}

- Mount Windows folders to enable file synchronization.
sudo mount -t cifs //192.168.0.167/_sync_ ~/share -o user=hoge,pass=hoge,dir_mode=0777,file_mode=0777
How to mount Windows 10 shared folders on Ubuntu 18.04 How to mount (sync) Windows 10 shared folders on Ubuntu 16.04
- Start Sinatra.
# dev.rb
require "sinatra"
require "open3"
require 'json'
require 'pry'
Encoding.default_external = 'UTF-8'
get "/" do
puts "y"
end
post "/androidsms" do
@body = request.body.read
json = JSON.parse(@body)
text = json["Text"]
stdout, stderr, statusCode = Open3.capture3(%(bash -ic "printf '#{text}' > /home/yuis/share/clipboard.txt || echo ''"))
puts stdout, stderr, statusCode
end
Start Sinatra:
sudo bundle exec ruby -o 0.0.0.0
-q dev.rb

- Set up IFTTT on the Android side.
Install the IFTTT app and enable the applet.
- Run a script on the WSL side to periodically monitor text data.
Execute the following script.
while true; do
echo -ne "$(isodate)\tNothing updated on the clipboard.\033[0K\r"
[[ -s "$SHAREDDIR/clipboard.txt" ]] && {
cat "$SHAREDDIR/clipboard.txt" | clip.exe ; > "$SHAREDDIR/clipboard.txt" ; printf "Copied text to clipboard." ;
}
sleep 2s
done

- Actually test the operation. Send an SMS from Android and check if the text is copied to the clipboard.
This should execute the flow of receiving SMS, sending to IFTTT, processing in Sinatra, file synchronization, and copying to clipboard in WSL. Since many tools are used, troubleshooting may be tedious, but if you have any problems, please ask.
Afterword
Finally, after obtaining text data in Ruby, you can use regular expressions and gsub to limit the strings copied to the clipboard. You can filter and customize the text as needed.