Get last SMS message from MacOS Messages database
The main purpose of this command is to get the text of the last SMS sent and copy it to the clipboard (for example, to get the code sent for two-factor authentication and past it in the login form).
The script is pre-configured for Okta authentication (that sends a message like Your verification code is XXXXX.), but should be adaptable to other forms of 2FA by passing the appropriate -pattern parameter.
mgot [-cli] [-copy] [-db path] [-filter] [-pattern pattern] [-service service]
where:
-cli
run in CLI mode (no tray icon)
-copy
copy result to clipboard (default true)
-db string
path to user Messages database (default "~/Library/Messages/chat.db")
-pattern string
pattern to search for (regexp) (default "(\\d+(-\\d+)?)")
-service string
message service to query (default "SMS")
- The standard location for the Messages database is ~/Library/Messages/chat.db
- The pattern is a regular expression that should match the field to extract.
- The Messages services for SMS is "SMS"
- By default the application run as a system tray icon, unless the -cli flag is passed. Also, by default the result is copied to the clipboard, unless the -copy flag is passed with value false (in which case the result is printed to stdout).