WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Running a script on click  (Read 258 times)

Offline edmazing

  • Newbie
  • *
  • Posts: 13
Running a script on click
« on: March 15, 2026, 09:51:06 PM »
So far I've managed to package a quick bash script to run a few commands. I tossed a few scripts into /usr/sbin
One to load a few packages and one to setup a p9 file system (setup & startp9 respectively)
Code: [Select]
xterm -title "setting up..." -e sh -c "tce-load -i gcc.tcz;tce-load -i linux-6.18_api_headers.tcz;" (and so on)
Code: [Select]
xterm -e sh -c "sudo insmod /lib/modules/6.18.2-tinycore/kernel/net/9p/p9net_virtio.ko.gz; sudo mkdir /home/tc/p9; sudo mount -t 9p -o trans=virtio,version=9p2000.L host9p /home/tc/p9"
Then I packaged a simple script setupdev
Code: [Select]
#!/bin/sh
xterm -e sh -c "setup; startp9"


(I didn't put the tcz's in onboot because the start up time becomes >5minutes for all the extensions)
tl;dr: Adding a bash script to an extension seems to loop and open a never ending number of terminal windows with just a single click of the icon.


Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12645
Re: Running a script on click
« Reply #1 on: March 15, 2026, 10:39:00 PM »
Hi edmazing
...
Code: [Select]
xterm -title "setting up..." -e sh -c "tce-load -i gcc.tcz;tce-load -i linux-6.18_api_headers.tcz;" (and so on) ...
You don't need to call tce-load over and over again:
Code: [Select]
tce-load -i gcc linux-6.18_api_headers (and so on)You can list multiple extensions in one command.
You don't need to include the  .tcz  when calling  tce-load.
If you are planning on compiling, the toolchain is called  compiletc.

Offline edmazing

  • Newbie
  • *
  • Posts: 13
Re: Running a script on click
« Reply #2 on: March 15, 2026, 10:43:07 PM »
That's good news. Not planning on compiling anything, just want to run a script when an icon is clicked... maybe I should be adjusting .wbar but I don't see a safe way to add an entry and an icon. I figured I'd create an extension for it but the extension seems to endlessly run the script once the desktop icon is pressed.

Offline edmazing

  • Newbie
  • *
  • Posts: 13
Re: Running a script on click
« Reply #3 on: March 16, 2026, 01:03:51 PM »
Still no luck.

I tried adding
Code: [Select]
if [ -f "home/tc/.wbar" ]; then to the bootlocal.sh script but it seems like it's not created the .wbar file yet.
Is there a better way to add an entry to .wbar when the flwm desktop starts up?

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 15531
Re: Running a script on click
« Reply #4 on: March 16, 2026, 01:45:21 PM »
Why note create an extension containing your script, a minimal *.desktop file and an icon?

i.e.
/usr/local/bin/myscript.sh
/usr/local/share/applications/myscript.desktop
/usr/local/share/pixmaps/myscript.png

Offline edmazing

  • Newbie
  • *
  • Posts: 13
Re: Running a script on click
« Reply #5 on: March 16, 2026, 01:52:25 PM »
I did try that but clicking the icon the script then opens windows without stopping.

The contents of myscript.sh
Code: [Select]
#!/bin/sh
xterm -e sh -c "cd /usr/sbin; startp9; setup;"
(setup and startp9 are both scripts I posted previously)

Offline edmazing

  • Newbie
  • *
  • Posts: 13
Re: Running a script on click
« Reply #6 on: March 16, 2026, 04:10:18 PM »
Ah I was using mksquashfs and it was just adding a user_1,user_2 folder to the existing myapp.tcz
There does seem to be a downside though that any dependencies need to be added to the onboot.lst so the boot time is huge once more.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12645
Re: Running a script on click
« Reply #7 on: March 16, 2026, 05:29:15 PM »
Hi edmazing
Try setting it up like this:

setupP9.sh
Code: [Select]
#!/bin/sh
ExtensionList="gcc linux-6.18_api_headers (and so on)"

echo "setting up..."

# Install extensions required for setting up, filter out "already installed" messages.
tce-load -i "$ExtensionList" 2>&1 | grep -v "already installed"

startP9.sh
Code: [Select]
#!/bin/sh
sudo insmod /lib/modules/6.18.2-tinycore/kernel/net/9p/p9net_virtio.ko.gz
sudo mkdir /home/tc/p9
sudo mount -t 9p -o trans=virtio,version=9p2000.L host9p /home/tc/p9

P9.sh
Code: [Select]
#!/bin/sh

xterm -e sh -c  "setupP9.sh; startP9.sh; exec sh" &

P9.desktop
Code: [Select]
[Desktop Entry]
Name=P9
Exec=P9.sh
Terminal=false
X-FullPathIcon=/usr/local/share/pixmaps/P9.png

Then:
Code: [Select]
chmod 755 P9.sh
chmod 755 setupP9.sh
chmod 755 startP9.sh
mkdir -p P9/usr/local/bin/
mkdir -p P9/usr/local/share/applications/
mkdir -p P9/usr/local/share/pixmaps/
cp *P9.sh P9/usr/local/bin/
cp P9.desktop P9/usr/local/share/applications/
# Copy the png for your icon to P9/usr/local/share/pixmaps/
mksquashfs P9 $P9.tcz -noappend

There should be no need to add anything to onboot.lst except P9.tcz.

Offline Leee

  • Wiki Author
  • Full Member
  • *****
  • Posts: 212
Re: Running a script on click
« Reply #8 on: March 18, 2026, 04:10:35 PM »
FWIW, I use jwm as my window manager and I have some scripts hooked up to buttons in the "tray" area.  The config goes into ~/.jwmrc-tray
Code: [Select]
     <TrayButton icon="/home/tc/dolly_48.png">
        <Button mask="1">exec:aterm  --geometry 100x25 -e ~tc/bin/firefix</Button>
        <Button mask="2">exec:aterm  --geometry 100x25 -e ~tc/bin/firefix --update</Button>
     </TrayButton>
In the above example, left click invokes the script w/o arguments and middle click invokes it with the --update argument.  The script opens in a terminal window which closes on exit.  If there are messages that need user attention, the script holds the window open by waiting for input.

Of course, if not using jwm, none of this applies.
core 16.0 x86_64