Desktop Alerts via Mobile Pushover (text alerts with image)

whoDAT

Member
Plus
Problem:
I have some complex scripts that work well on TOS desktop charts, however they do not alert through TOS scans and are not available on TOS mobile. I would like to receive real-time alerts on my mobile, as that is available when I'm away from the computer.

Solution:
1) Use a computer to run TOS. Run multiple charts with multiple studies that trigger alerts (with sound).
2) Use AutoHotKey to listen if a sound occurs. If a sound occurs, take a screenshot.
3) Use Pushover (this service costs $5 as a one-time purchase) to send the screenshot to my mobile phone (in this case an iPhone.)

Specifics:
For the computer to run TOS. I use a headless mini PC that I control with TeamViewer. The PC will need to run Windows 10+ for TOS. These mini PCs are available for about $150. Alternatively, you could use your main PC or an old laptop or whatever fits your needs and budget.
- You will need to install AutoHotKey. https://www.autohotkey.com/download/
- You will need to download the Vista Audio AutoHotKey library. https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/VA.ahk
- You will need to install IrFanView, an image processing software. https://www.irfanview.com/64bit.htm
- You will need to get a Pushover account. https://pushover.net/

Limitations:
- There alot of moving pieces to these scripts, they need you to install some software and get names and file locations correct.
- This is about the cheapest way to reliably get image text messages to your mobile device, but it is not free.
- Any sound on the computer will trigger a Pushover message. So kill all those Windows alerts. Also you will get alerts when you place orders on TOS and other messages from TOS.


This AutoHotKey program "Listen to Pushover" listens for audio: When it hears your alert ding, it will create a screenshot, and then trigger a Pushover message to be sent. It also has a quick method to close or restart TOS. Please note that there are 4 file locations that are important to code in correctly in the program.
AutoHotKey programs are just plain text files that you save with the "*.ahk" file name. Name the program something like "ListenPushover.ahk"

Code:
; REPLACE THE BELOW WITH THE LOCATION OF YOUR VISTA AUDIO AHK LIBRARY
#Include VA.ahk

triggervol = 0.02
audioMeter := VA_GetAudioMeter()
VA_IAudioMeterInformation_GetMeteringChannelCount(audioMeter, channelCount)
VA_GetDevicePeriod("capture", devicePeriod)

Gui, Font, s10
Gui, Add, Text,, Listen / Send
Gui, Add, Radio, vscript gf1, Press to Run Listen/Pushover
Gui, Add, Radio,         gf2, Press to Pause
Gui, Add, Radio,         gf3, Press to Start TOS
Gui, Add, Radio,         gf4, Press to Close TOS
Gui, Add, Radio,         gf5, Press to Close Listen/Pushover
Gui, Show, w220, Test

f1::
loop{
    VA_IAudioMeterInformation_GetPeakValue(audioMeter, peakValue)
    while (peakValue>triggervol)
        {
; Hard close Powershell if it didnt close on its own  
        if WinExist("Select Windows PowerShell")
            {
            WinActivate
            WinClose
            }
        click
       
; REPLACE THE BELOW WITH YOUR LOCATION FOR THE SCREENSHOT SCRIPT      
        Run %a_desktop%\TOS_Scripts\screenshot.ahk
        Sleep, 500

; REPLACE THE BELOW WITH THE LOCATION OF YOUR PUSHOVER POWERSHELL SCRIPT
        Run PowerShell.exe -File %a_desktop%\TOS_Scripts\PushoverSend.ps1
        Sleep, 500  
        VA_IAudioMeterInformation_GetPeakValue(audioMeter, peakValue)
        }

Sleep, 100
}
Return

f2:: Sleep, 100

; REPLACE THE BELOW WITH THE LOCATION FOR YOUR THINKORSWIM APPLICATION LOCATION
f3:: Run C:\Users\XXX\AppData\Local\thinkorswim\thinkorswim.exe

f4:: WinClose, thinkorswim

f5:: ExitApp


This AutoHotKey program will take the screen shot using IrFanView (The SCREENSHOT SCRIPT used in the prior script.). Please note you need to hard code the location of IrFanView as installed on your computer. You may need to change the window size of the screenshot. In this case it is taking a image from (0,0) to (2000,1400) and then resizing it to (200 x 140) with a 60% compression (/capture=3 /crop=(0,0,2000,1400) /resize(200,140) /jpgq=60). This program also creates a folder on your desktop for screenshots. Again, save this as something like "screenshot.ahk"

Code:
SetTitleMatchMode, 2
WinActivate, thinkorswim

Destination=%a_desktop%\SCREENSHOTS
IfNotExist, %Destination%            ; if there is not already a destination folder create one
  FileCreateDir, %Destination%

FormatTime, DateTime,, yyyy-MM-dd_HHmmss
ivParams = /capture=3 /crop=(0,0,2000,1400) /resize(200,140) /jpgq=60 /convert=%Destination%\capture_$U(%DateTime%).jpg

; REPLACE THE BELOW WITH THE LOCATION OF YOUR IRFANVIEW INSTALLATION
Runwait, "%A_ProgramFiles%\IrfanView\i_view64.exe" "%ivParams%"

Return


Last code is a PowerShell script. This sends the last screenshot image file to the Pushover service. This script is called in the first AutoHotKey script, as the PushoverSend.ps1. Name it what you want (with the *.ps1 -- PowerShell script). Make sure to put in your Pushover application token, and User Key. Also you need to hard code the location of your screenshot folder.
Code:
# Pushover API details
$PushoverApiUrl = "https://api.pushover.net/1/messages.json"
$ApplicationToken = "zzzzzzzzzzzzzzzzzzzzzzzzzzz" # Replace with your actual application token
$UserKey = "zzzzzzzzzzzzzzzzzzzzzzzzzz" # Replace with your actual user key
$ImageDir = "C:\Users\zzzzzzzzzzzzzzz\OneDrive\Desktop\SCREENSHOTS\"
# Notification details
$Message = "TOS Alert via Pushover"
$Title = "TOS Alert"

# Find the last file added to the directory
$file = Get-ChildItem -Path $ImageDir| Sort LastWriteTime -Descending | Select-Object -First 1
$AttachmentPath = $ImageDir + $file
[System.Windows.MessageBox]::Show($AttachmentPath)

# Create the body for the POST request
$Body = @{
    token = $ApplicationToken
    user = $UserKey
    message = $Message
    title = $Title
}

# Add the attachment if the file exists
if (Test-Path $AttachmentPath) {
    $Attachment = Get-Item $AttachmentPath
    $FileName = $Attachment.Name
    $FileType = "image/jpeg" # Adjust based on your attachment type (e.g., image/png, application/pdf)

    # Use a multipart/form-data content type for file uploads
    # This requires building the body as a byte array for Invoke-RestMethod -ContentType "multipart/form-data"
    $Boundary = [System.Guid]::NewGuid().ToString()
    $NewLine = "`r`n"
    $Headers = @{ "Content-Type" = "multipart/form-data; boundary=$Boundary" }

    $Content = "--$Boundary$NewLine"
    $Content += "Content-Disposition: form-data; name=`"token`"$NewLine$NewLine$ApplicationToken$NewLine"
    $Content += "--$Boundary$NewLine"
    $Content += "Content-Disposition: form-data; name=`"user`"$NewLine$NewLine$UserKey$NewLine"
    $Content += "--$Boundary$NewLine"
    $Content += "Content-Disposition: form-data; name=`"message`"$NewLine$NewLine$Message$NewLine"
    $Content += "--$Boundary$NewLine"
    $Content += "Content-Disposition: form-data; name=`"title`"$NewLine$NewLine$Title$NewLine"
    $Content += "--$Boundary$NewLine"
    $Content += "Content-Disposition: form-data; name=`"attachment`"; filename=`"$FileName`"$NewLine"
    $Content += "Content-Type: $FileType$NewLine$NewLine"
    $ContentBytes = [System.Text.Encoding]::ASCII.GetBytes($Content)
    $FileBytes = [System.IO.File]::ReadAllBytes($AttachmentPath)
    $EndBoundaryBytes = [System.Text.Encoding]::ASCII.GetBytes("$NewLine--$Boundary--$NewLine")

    $RequestBody = New-Object byte[] ($ContentBytes.Length + $FileBytes.Length + $EndBoundaryBytes.Length)
    [System.Buffer]::BlockCopy($ContentBytes, 0, $RequestBody, 0, $ContentBytes.Length)
    [System.Buffer]::BlockCopy($FileBytes, 0, $RequestBody, $ContentBytes.Length, $FileBytes.Length)
    [System.Buffer]::BlockCopy($EndBoundaryBytes, 0, $RequestBody, $ContentBytes.Length + $FileBytes.Length, $EndBoundaryBytes.Length)

    # Send the request with the attachment
    try {
        $Response = Invoke-RestMethod -Uri $PushoverApiUrl -Method Post -Headers $Headers -Body $RequestBody
        Write-Host "Pushover notification with attachment sent successfully."
        $Response | ConvertTo-Json
    }
    catch {
        Write-Error "Failed to send Pushover notification with attachment: $($_.Exception.Message)"
    }
} else {
    Write-Warning "Attachment file not found at '$AttachmentPath'. Sending notification without attachment."
    # Send the request without attachment if file not found
    try {
        $Response = Invoke-RestMethod -Uri $PushoverApiUrl -Method Post -Body $Body
        Write-Host "Pushover notification sent successfully (without attachment)."
        $Response | ConvertTo-Json
    }
    catch {
        Write-Error "Failed to send Pushover notification: $($_.Exception.Message)"
    }
}
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
207 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top