Is there a way to grab text from the "$" variable from AHK?

Here you are welcome to discuss items of general interest related to Push2Run
Post Reply
dcjack86
Posts: 4
Joined: Thu Feb 10, 2022 11:55 pm

Is there a way to grab text from the "$" variable from AHK?

Post by dcjack86 »

I'm trying to write a script that will fill in text using a line in Autohotkey

*********************************************************************************
Run, C:\Users\cwimm\Desktop\Spotify.exe

Sleep 2000

if WinExist("Spotify Premium")
WinActivate

Send, {Ctrl down}l{Ctrl up}

Click, 707 33

FileRead, Clipboard, C:\Users\cwimm\Dropbox\Apps\Push2Run\Command.txt

Send, ^v

Sleep 4000

Click, 726 156
**********************************************************************************

Everything is working fine except the part where I try to copy/paste the text from the Dropbox file. I imagine the file is created and then immediately deleted once the commands are pushed to Push2Run, so is there a way to still get that text pulled into my AHK script?
RobLatour
Site Admin
Posts: 1003
Joined: Mon Feb 19, 2018 11:43 am

Re: Is there a way to grab text from the "$" variable from AHK?

Post by RobLatour »

I'm afraid I haven't used AutoHotKey much, however assuming that you can run an autohotkey script file, passing into it parameters, then yes.

You would just need to identify the auto hotkey script file in your Push2Run card's open field, and then pass into it the words you have spoken via the Push2Run card's parameters field containing just a $.

Also, from within the autohotkey script, you would need to parse out the incoming parameter(s) and handle them however you like.

Attached are example script files (below) of how to do this with autoit and vbs scripts. Unfortunately, I don't have an autohotkey example as I haven't used it enough to work that out with it.

Hope this at least gets you going in the right direction.
scripts.zip
(1.54 KiB) Downloaded 103 times
dcjack86
Posts: 4
Joined: Thu Feb 10, 2022 11:55 pm

Re: Is there a way to grab text from the "$" variable from AHK?

Post by dcjack86 »

I wanted to share my solution here.

I ended up just grabbing the variable information directly from the file that IFTTT creates and sends to Dropbox. Luckily even though the file self-destructs, it exists long enough to copy the relevant string.

**********************************************************************************************************************
FileReadLine, Songtitle, C:\Users\cwimm\Dropbox\Apps\Push2Run\Command.txt, 2

String := Songtitle
StringTrimLeft, PasteSong, String, 8

Run, C:\Users\cwimm\Desktop\Spotify.exe

if WinExist("ahk_exe Spotify.exe")
WinActivate, ahk_exe Spotify.exe

WinSet, AlwaysOnTop, On, ahk_exe Spotify.exe

WinActivate, ahk_exe Spotify.exe

WinMaximize, ahk_exe Spotify.exe

Send {Ctrl down}l{Ctrl up}

Click, 707 31

Sleep 250

Send %PasteSong%

Sleep 1000

Click, 726 156, ahk_exe Spotify.exe

WinSet, AlwaysOnTop, Off, ahk_exe Spotify.exe
**********************************************************************************************************************

I do want to clean this up by using mouse clicks that don't move the cursor or some other method to "click" the wanted objects, but I'm gonna mosey on over to AHK forums to get that part done.

SUMMARY: Basically what this allows is for Google Assistant to work in Windows and Open/Highlight Spotify, input the song/artist search parameters and play the most relevant result first. This is made possible by using IFTTT (Combining the applet for Google Assistant - Ingredient text and the applet for Dropbox - Create text file) and Push2Run as the interpreter for the file that Dropbox receives from Google Assistant output. It works!

Also, I think it's awesome that you take the time to help people with this stuff and I want you to know that you're greatly appreciated. This project was a ton of fun for me.

P.S. I realize you know most of what's in this post in terms of Push2Run, but I figured if someone stumbles across it and wants to do something similar they might be able to use this post as a tutorial or at least a bread crumb.
Post Reply