Score:1

.desktop files to launch shell scripts

us flag

I am trying to create two .desktop entries to launch shell scripts.

the shell scripts fullLaunch.sh and tracepen.sh should be executed. Both run when launched from the terminal.

They launch multiple other files, including ros launchfiles and other shell scripts.

tracepen.desktop looks like this:

[Desktop Entry]
Type=Application
Exec=bash /home/qiaoyue/happyspace/src/fmp_robot_shellscripts/robot/tracepen.sh
Icon=/home/qiaoyue/happyspace/src/fmp_robot_shellscripts/icons/tracepen.png
Name=Trace Pen
Terminal=true

tracepen.sh:

#!/bin/bash

# Check if SteamVR is running
if pgrep -x "vrmonitor" > /dev/null
then
    echo "SteamVR is running"
else
    echo "SteamVR is not running, starting it now..."
    xdg-open steam://rungameid/250820 & disown
    echo "Waiting for SteamVR to start..."
    
    # Wait for SteamVR to start
    while ! pgrep -x "vrmonitor" > /dev/null
    do
        sleep 1
    done
fi

echo "Starting up tracepen"

rosrun fmp_tracepen_node tracepen_node.py

bahavior: steam is started, but in the end i am not left with an open terminal running the tracepen_node.py. Starting it directly with ./tracepen.sh does.


fullLaunch.desktop (basically the same):

[Desktop Entry]
Type=Application
Exec=/home/qiaoyue/happyspace/src/fmp_robot_shellscripts/robot/fullLaunch.sh
Icon=/home/qiaoyue/happyspace/src/fmp_robot_shellscripts/icons/launch.png
Name=Robot
Terminal=true

fulLaunch.sh:

#!/bin/bash

wait_for_topic() {
    TOPIC=$1
    while true; do
        if rostopic list | grep -q "$TOPIC"; then
            break
        else
            sleep 0.5
        fi
    done
}

# Check if roscore is already running, if yes then kill it
if (rosnode list &> /dev/null); then
    killall -9 roscore
    killall -9 rosmaster
fi

# Start roscore in a new tab
nohup roscore &> /dev/null &

# Wait for roscore to start
while ! (rosnode list &> /dev/null); do
    sleep 0.5
done

gnome-terminal -- bash -c "roslaunch fmp_launch trajServer.launch"

# Wait for move_group to start
wait_for_topic "/sequence_move_group"

gnome-terminal --tab -- bash -c "rosrun fmp_move_traj trajectory_server.py"
gnome-terminal --tab -- bash -c "rosrun fmp_move_traj pose_server.py"
gnome-terminal --tab -- bash -c "rviz -d  $(rospack find fmp_move_traj)/rvizLaunch/realRobot.rviz"
gnome-terminal --tab -- bash -c "rosrun fmp_move_traj buttons.py"
gnome-terminal --tab -- bash -c "rosrun fmp_move_traj poseModifier.py"

the .desktop launches two terminals, one with an error that immediately terminates.

Score:1
ph flag

If you're expecting a terminal to pop open, you'll need to launch it yourself and then run the command in that terminal. Try replacing:

rosrun fmp_tracepen_node tracepen_node.py

with something like

gnome-terminal -x rosrun fmp_tracepen_node tracepen_node.py
Florian Schneider avatar
us flag
But isn't this what my fulllaunch.sh script is doing anyway? All commands are run in gnome terminal tabs.
ckhan avatar
ph flag
I see now that your second script does use a terminal for some of the commands. Lets separate your two problems. Does my suggestion above address your expectation that a terminal needs to be opened for your `tracepen_node.py` script?
ckhan avatar
ph flag
More generally: I think your problems are about the unexpected absence of controlling terminals for processes you are starting from these scripts. Notes in https://askubuntu.com/questions/436891/create-a-desktop-file-that-opens-and-execute-a-command-in-a-terminal might help.
Florian Schneider avatar
us flag
I was able to get the tracepen.sh working( using Exec=gnome-terminal -e "bash -c '/home/qiaoyue/happyspace/src/fmp_robot_shellscripts/robot/tracepen.sh'"), but the fullLaunch.sh still makes problems.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.