Do specific operations when I arrive at a specific location? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
serbring
Posts: 18
Joined: 04 Oct 2017, 11:46

Do specific operations when I arrive at a specific location?

06 Jan 2018, 15:04

hi all,

I am developing a script that should do some operations when I arrive at the office. No problem to do the operations, but I don't know how set the trigger. What can I use to check the location?

Thanks

Best regards.
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Do specific operations when I arrive at a specific location?

06 Jan 2018, 15:15

If the IP address at your office is static, that would do it. It is found in the built-in variable A_IPAddress1 (and 2, 3, and 4 for multiple network adaptors).
serbring
Posts: 18
Joined: 04 Oct 2017, 11:46

Re: Do specific operations when I arrive at a specific location?

06 Jan 2018, 15:50

boiler wrote:If the IP address at your office is static, that would do it. It is found in the built-in variable A_IPAddress1 (and 2, 3, and 4 for multiple network adaptors).
that is a good idea, but the IP is not static. I would you the network SSID. I have found this code line:

Code: Select all

Runwait %comspec% /c netsh wlan show interface | clip,,hide
Unfortunately, the result of netsh is put into the clipboard and I can't do it in my code, as this line is inside a SetTimer function. Is there any way to put the network info in a variable?

Thanks
serbring
Posts: 18
Joined: 04 Oct 2017, 11:46

Re: Do specific operations when I arrive at a specific location?

06 Jan 2018, 15:53

I didn't know this, thanks. Unfortunately, I cannot use it as I am developing a computer log, so I need to save the location of the PC and the trigger to start the log is the arrival at the office
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Do specific operations when I arrive at a specific location?

06 Jan 2018, 16:01

serbring wrote:

Code: Select all

Runwait %comspec% /c netsh wlan show interface | clip,,hide
Unfortunately, the result of netsh is put into the clipboard and I can't do it in my code, as this line is inside a SetTimer function. Is there any way to put the network info in a variable?
If it's in the clipboard, it's in the AHK built-in variable called Clipboard, which you then can assign to a variable. Is there a reason you can't do that?
serbring
Posts: 18
Joined: 04 Oct 2017, 11:46

Re: Do specific operations when I arrive at a specific location?

06 Jan 2018, 16:03

boiler wrote:
serbring wrote:

Code: Select all

Runwait %comspec% /c netsh wlan show interface | clip,,hide
Unfortunately, the result of netsh is put into the clipboard and I can't do it in my code, as this line is inside a SetTimer function. Is there any way to put the network info in a variable?
If it's in the clipboard, it's in the AHK built-in variable called Clipboard, which you then can assign to a variable. Is there a reason you can't do that?
my script logs the name of the active windows once every 1s. In addiction, it should check the SSID. If Runwait uses the clipboard, then the clipboard is useless for any other activity as every 1s it is loaded data coming from this line:

Code: Select all

Runwait %comspec% /c netsh wlan show interface | clip,,hide
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Do specific operations when I arrive at a specific location?  Topic is solved

06 Jan 2018, 16:24

Code: Select all

#NoEnv

output := cmd("netsh wlan show interface")
MsgBox % output

; Example output parsing
Loop, Parse, output, `n, `r
    result .= (A_Index=3 || A_Index=4) ? A_LoopField . "`n" : ""
MsgBox % result

ExitApp

cmd(str)
{    
    DetectHiddenWindows, On
    Run %ComSpec%,, Hide, pid
    WinWait, ahk_pid %pid%
    DllCall("AttachConsole", "UInt", pid)
    WshShell := ComObjCreate("WScript.Shell")
	oExec := WshShell.Exec(ComSpec " /k/q echo off")
    oExec.StdIn.WriteLine(str . "`nexit")
	cmdoutput := oExec.StdOut.ReadAll()
    DllCall("FreeConsole")
    Process, Close, %pid%
    DetectHiddenWindows, Off
    return cmdoutput
}
HTH
serbring
Posts: 18
Joined: 04 Oct 2017, 11:46

Re: Do specific operations when I arrive at a specific location?

06 Jan 2018, 17:15

Xtra wrote:

Code: Select all

#NoEnv

output := cmd("netsh wlan show interface")
MsgBox % output

; Example output parsing
Loop, Parse, output, `n, `r
    result .= (A_Index=3 || A_Index=4) ? A_LoopField . "`n" : ""
MsgBox % result

ExitApp

cmd(str)
{    
    DetectHiddenWindows, On
    Run %ComSpec%,, Hide, pid
    WinWait, ahk_pid %pid%
    DllCall("AttachConsole", "UInt", pid)
    WshShell := ComObjCreate("WScript.Shell")
	oExec := WshShell.Exec(ComSpec " /k/q echo off")
    oExec.StdIn.WriteLine(str . "`nexit")
	cmdoutput := oExec.StdOut.ReadAll()
    DllCall("FreeConsole")
    Process, Close, %pid%
    DetectHiddenWindows, Off
    return cmdoutput
}
HTH

That's work. Thanks
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Do specific operations when I arrive at a specific location?

06 Jan 2018, 18:05

Xtra wrote:

Code: Select all

#NoEnv

output := cmd("netsh wlan show interface")
MsgBox % output

; Example output parsing
Loop, Parse, output, `n, `r
    result .= (A_Index=3 || A_Index=4) ? A_LoopField . "`n" : ""
MsgBox % result

ExitApp

cmd(str)
{    
    DetectHiddenWindows, On
    Run %ComSpec%,, Hide, pid
    WinWait, ahk_pid %pid%
    DllCall("AttachConsole", "UInt", pid)
    WshShell := ComObjCreate("WScript.Shell")
	oExec := WshShell.Exec(ComSpec " /k/q echo off")
    oExec.StdIn.WriteLine(str . "`nexit")
	cmdoutput := oExec.StdOut.ReadAll()
    DllCall("FreeConsole")
    Process, Close, %pid%
    DetectHiddenWindows, Off
    return cmdoutput
}
HTH
That's quite amazing! Thx :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CuriousDad, rc76 and 222 guests