0

I use my phone as a speaker over WiFi for my pc so after starting kubuntu 24.04 i always have to open konsole app to search my IP then start a audio-share app with that ip to share sound of my PC to my mobile phone ...i want to make a sh script to do that for me

can anybody help me write a script so that it will open terminal(konsole) window execute my particular command which is in my case this below

ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'

take result of that above command then start an audio share app with arguments of above command.

like results of that ifconfig command is 192.168.1.29 ,,, script will take that ip result and start my audio share app using that ip like this

./audioshare -b 192.168.1.29

also i would like to add that script to system startup Thanks so much.

kos
  • 41,268

1 Answers1

0

Note that this does exactly what you asked for, which is leaving a Konsole instance running the script for the whole duration of the script; is this really what you want?


I would do something like this:

#!/usr/bin/env bash

ifname=wlo1

ip=$( ip -j address | jq -r --arg ifname "${ifname}" ' .[] | select(.ifname==$ifname).addr_info[] | select(.family=="inet").local ' )

konsole -e "bash -c '/full/path/to/audioshare/script -b "${ip}"'"

Replace wlo1 with the name of the network interface connected to the network the phone is in (as reported by ip address) and /full/path/to/audioshare/script with the full path to the audioshare script.

To run the script at startup, place the script (let's call it connect_speaker.sh) somewhere (I suggest ~/bin), make it executable (chmod +x ~/bin/connect_speaker.sh) then, in System settings:

  • Click on "Startup and Shutdown"
  • Click on "Autostart"
  • Click on "+ Add..."
  • Select "+ Add login script..."
  • Navigate to ~/bin
  • Select connect_speaker.sh
  • Click on "Open"

screenshot

kos
  • 41,268