It is currently December 6th, 2022, 1:41 pm

Connected Bluetooth device (RegExpSubstitute)

Get help with creating, editing & fixing problems with skins
User avatar
StArL0rd84
Posts: 398
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Connected Bluetooth device (RegExpSubstitute)

Post by StArL0rd84 »

I found this Bluetooth command line utility that lists paired and connected devices.
But I want to treat the output to only show the name of the connected device using RegExpSubstitute.
In this case it should be 'OnePlus Bullets Wireless Z'. This is where I need help...

The output looks like this:

Code: Select all

Start discovering devices for 10 seconds
-------------------------------------------------------------------------
|LE|dc:b7:2e:57:e1:c3|Paired   |<Unknown>                               |
|LE|4c:9f:6d:cd:be:d4|         |<Unknown>                               |
|LE|5d:62:41:e0:9e:d2|         |<Unknown>                               |
|LE|50:c3:46:b9:de:09|         |<Unknown>                               |
|  |00:14:be:00:8e:36|Paired   |BW-FYE5 R                               |
|  |00:14:be:19:7c:94|Paired   |BW-FYE5 R                               |
|  |b2:76:68:66:7f:c7|Paired   |KN320                                   |
|  |00:1f:20:92:9d:9e|Paired   |Logitech K810                           |
|LE|c1:56:ae:74:9c:68|Paired   |MX Master                               |
|  |98:09:cf:d3:32:93|Connected|OnePlus Bullets Wireless Z              |
|LE|98:09:cf:d3:32:93|Connected|OP Headset                              |
|  |dc:b7:2e:57:e1:c3|Paired   |POCO X3 NFC                             |
|  |d0:bc:c1:e0:c0:a6|Paired   |Wireless Controller                     |
-------------------------------------------------------------------------
The CMD utility:
https://github.com/PolarGoose/BluetoothDevicePairing

Code: Select all

LeftMouseUpAction=[!CommandMeasure mBluetoothDevicePairing "run"]

[mBluetoothDevicePairing]
Measure=Plugin
Plugin=RunCommand
Program=#@#Programs\BluetoothDevicePairing\BluetoothDevicePairing.exe
Parameter=discover
OutputType=ANSI
DynamicVariables=1
UpdateDivider=-1
RegExpSubstitute=1
Substitute=
Last edited by StArL0rd84 on September 25th, 2022, 5:25 pm, edited 1 time in total.
User avatar
tass_co
Posts: 429
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

Re: Connected Bluetooth device

Post by tass_co »

StArL0rd84 wrote: September 25th, 2022, 12:10 pm The output looks like this:

Code: Select all

Start discovering devices for 10 seconds
-------------------------------------------------------------------------
|LE|dc:b7:2e:57:e1:c3|Paired   |<Unknown>                               |
|LE|4c:9f:6d:cd:be:d4|         |<Unknown>                               |
|LE|5d:62:41:e0:9e:d2|         |<Unknown>                               |
|LE|50:c3:46:b9:de:09|         |<Unknown>                               |
|  |00:14:be:00:8e:36|Paired   |BW-FYE5 R                               |
|  |00:14:be:19:7c:94|Paired   |BW-FYE5 R                               |
|  |b2:76:68:66:7f:c7|Paired   |KN320                                   |
|  |00:1f:20:92:9d:9e|Paired   |Logitech K810                           |
|LE|c1:56:ae:74:9c:68|Paired   |MX Master                               |
|  |98:09:cf:d3:32:93|Connected|OnePlus Bullets Wireless Z              |
|LE|98:09:cf:d3:32:93|Connected|OP Headset                              |
|  |dc:b7:2e:57:e1:c3|Paired   |POCO X3 NFC                             |
|  |d0:bc:c1:e0:c0:a6|Paired   |Wireless Controller                     |
-------------------------------------------------------------------------
I downloaded the app and tried it.
Windows cannot allow you to execute your application because there is no permission.
You need to allow the app on Windows.

Code: Select all

[MeaRun]
Measure=Plugin
Plugin=RunCommand
Program=cmd
Parameter="BluetoothDevicePairing.exe" discover
State=Hide
OutputType=ANSI
OutputFile=Deneme.txt
TimeOut=3000
Deneme.txt (language turkish)

Code: Select all

Microsoft Windows [Version 10.0.19044.2006]
(c) Microsoft Corporation. Tm haklar sakldr.

C:\Users\----------\Documents\Rainmeter\Skins\005>More? 'c' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\---------\Documents\Rainmeter\Skins\005>More? 
I don't know where i going from here, but i promise it won't be boring... :great:
User avatar
StArL0rd84
Posts: 398
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Connected Bluetooth device

Post by StArL0rd84 »

tass_co wrote: September 25th, 2022, 3:50 pm I downloaded the app and tried it.
Windows cannot allow you to execute your application because there is no permission.
You need to allow the app on Windows.

Code: Select all

[MeaRun]
Measure=Plugin
Plugin=RunCommand
Program=cmd
Parameter="BluetoothDevicePairing.exe" discover
State=Hide
OutputType=ANSI
OutputFile=Deneme.txt
TimeOut=3000
Deneme.txt (language turkish)

Code: Select all

Microsoft Windows [Version 10.0.19044.2006]
(c) Microsoft Corporation. Tm haklar sakldr.

C:\Users\----------\Documents\Rainmeter\Skins\005>More? 'c' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\---------\Documents\Rainmeter\Skins\005>More? 
Not exactly sure why you where not able to use it on your system without "allowing" it. maybe you are not admin?
Anyways, I made a example skin for you to try out.
BtDiscovery_1.rmskin
Should look like this:
output.png
The program works fine on my machine with no issues.
Although it takes about 10 seconds for the measure to return the list. (can live with that)
Ultimately I just need help with the syntax in the RegExpSubstitute,
so I just end up with whatever name is next to the connected status in the result.
You do not have the required permissions to view the files attached to this post.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4885
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Connected Bluetooth device

Post by eclectic-tech »

StArL0rd84 wrote: September 25th, 2022, 12:10 pm I found this Bluetooth command line utility that lists paired and connected devices.
But I want to treat the output to only show the name of the connected device using RegExpSubstitute.
In this case it should be 'OnePlus Bullets Wireless Z'. This is where I need help...
Didn't try your program, but this may get you what you want.

Code: Select all

RegExpSubstitute=1
Substitute="^.*\|Connected\|(.*)\|\|LE.*$":"\1"
Adding it to your RunCommand measure should return the first connected device name as the value of the measure.
User avatar
StArL0rd84
Posts: 398
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Connected Bluetooth device

Post by StArL0rd84 »

eclectic-tech wrote: September 25th, 2022, 5:22 pm Didn't try your program, but this may get you what you want.

Code: Select all

RegExpSubstitute=1
Substitute="^.*\|Connected\|(.*)\|\|LE.*$":"\1"
Adding it to your RunCommand measure should return the first connected device name as the value of the measure.
Looked like it would work , but I'm afraid it doesn't.
Spits out same result, no changes.

Tried with parentages like this too:

Code: Select all

RegExpSubstitute=1
Substitute="^(.*\|Connected\|)(.*)(.*\|\|LE.)*$":"\1"
A script measure to quickly test syntax:

Code: Select all

[MeasureString]
Measure=String
String=|  |98:09:cf:d3:32:93|Connected|OnePlus Bullets Wireless Z              |
RegExpSubstitute=1
Substitute="^.*\|Connected\|(.*)\|\|LE.*$":"\1"
;Substitute=" ":"-""^.*Connected\|(.*)-.*$":"\1"
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4885
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Connected Bluetooth device

Post by eclectic-tech »

StArL0rd84 wrote: September 25th, 2022, 5:37 pm Looked like it would work , but I'm afraid it doesn't.
Spits out same result, no changes.

Tried with parentages like this too:

Code: Select all

RegExpSubstitute=1
Substitute="^(.*\|Connected\|)(.*)(.*\|\|LE.)*$":"\1"
A script measure to quickly test syntax:

Code: Select all

[MeasureString]
Measure=String
String=|  |98:09:cf:d3:32:93|Connected|OnePlus Bullets Wireless Z              |
RegExpSubstitute=1
Substitute="^.*\|Connected\|(.*)\|\|LE.*$":"\1"
;Substitute=" ":"-""^.*Connected\|(.*)-.*$":"\1"
Try:

Code: Select all

RegExpSubstitute=1
Substitute=".*\|Connected\|(.*)\|":"\1"
This worked for me using your skin... returned my Buetooth headphones.
User avatar
StArL0rd84
Posts: 398
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Connected Bluetooth device

Post by StArL0rd84 »

eclectic-tech wrote: September 25th, 2022, 6:08 pm Try:

Code: Select all

RegExpSubstitute=1
Substitute=".*\|Connected\|(.*)\|":"\1"
This worked for me using your skin... returned my Buetooth headphones.
For me, that looks like this for me:
output2.png
It does not output the name alone.


The following works perfectly for me in a string measure:

Code: Select all

[MeasureString]
Measure=String
String=|  |98:09:cf:d3:32:93|Connected|OnePlus Bullets Wireless Z              |
RegExpSubstitute=1
Substitute="^.*\d\d\|Connected\|(.*)\|.*$":"\1"
But not in the main measure, so im trying this right now:

Code: Select all

[mBluetoothDevicePairing]
Measure=Plugin
Plugin=RunCommand
Program=#BluetoothDevicePairing#
Parameter=discover
OutputType=ANSI
DynamicVariables=1
RegExpSubstitute=1
Substitute="^.*\d\d\|Connected\|(.*)\|#CRLF#\|.*$":"\1"
You do not have the required permissions to view the files attached to this post.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4885
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Connected Bluetooth device (RegExpSubstitute)

Post by eclectic-tech »

It looks like you may need an additional substitution to handle eliminating devices that are 'Paired' but not 'Connected'.
I'm about at the limit of my knowledge on RegExp :oops:

Hopefully someone else may jump in with help,
or our 'Trial'n Error' method will eventually produce the desired result :thumbup:
User avatar
StArL0rd84
Posts: 398
Joined: February 8th, 2015, 10:07 pm
Location: EU, Denmark.

Re: Connected Bluetooth device (RegExpSubstitute)

Post by StArL0rd84 »

eclectic-tech wrote: September 25th, 2022, 6:51 pm It looks like you may need an additional substitution to handle eliminating devices that are 'Paired' but not 'Connected'.
I'm about at the limit of my knowledge on RegExp :oops:

Hopefully someone else may jump in with help,
or our 'Trial'n Error' method will eventually produce the desired result :thumbup:
Thank you for the assistance.
I'm sure we made some headway.
User avatar
tass_co
Posts: 429
Joined: May 4th, 2020, 3:01 pm
Location: Ankara, TURKEY

Re: Connected Bluetooth device (RegExpSubstitute)

Post by tass_co »

StArL0rd84 wrote: September 25th, 2022, 7:21 pm Thank you for the assistance.
I'm sure we made some headway.
Can you try and write the result?
26.09.2022 - 00.27.47-About Rainmeter.png

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
OnRefreshAction=[!CommandMeasure mBluetoothDevicePairing "run"]
AccurateText=1

[Metadata]
Name=
Author=
Information=
Version=
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0

[Variables]
BluetoothDevicePairing=#@#BluetoothDevicePairing.exe
; https://github.com/PolarGoose/BluetoothDevicePairing

[mBluetoothDevicePairing]
Measure=Plugin
Plugin=RunCommand
Program=#BluetoothDevicePairing#
Parameter=discover
OutputType=ANSI
DynamicVariables=1
UpdateDivider=-1

[MeaStr]
Measure=String
String=[mBluetoothDevicePairing]
RegExpSubstitute=1
Substitute="#CRLF#":"",".*\|Connected\|(.*)\s|.*":"\1","(..)$":"","\s+$":""
DynamicVariables=1

[MeterString]
Meter=String
MeasureName=MeaStr
X=0
Y=0
FontColor=255,255,255,255
FontFace=Segoe UI
FontSize=17
StringEffect=Shadow
SolidColor=0,0,0,255
AntiAlias=1
Text=Output: %1
DynamicVariables=1
You do not have the required permissions to view the files attached to this post.
I don't know where i going from here, but i promise it won't be boring... :great: