This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Launch shortcut of Konsole with parameters

Tags: None
(comma "," separated)
FlowXP
Registered Member
Posts
27
Karma
0
Hello all, I used a little command line on Linux Mint.
Code: Select all
gnome-terminal -- /bin/sh -c 'sleep 1; echo "Sync ! :"; sync; sleep 5'

I want to adapt it to konsole but this way doesn't work, it just opens two terminals :
Code: Select all
konsole -- /bin/sh -c 'sleep 1; echo "Sync ! :"; sync; sleep 5'


Can you help me ? I use it after copying large number of files to USB and I want to be sure there is no data left in cache.
Thanks


finally on KDE Neon !!
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
Hi!

There is a runCommand-method in Konsole available via dbus. I'm using yakuake as dropdown-terminal, but it will work for konsole too if you replace yakuake with konsole-$id (and of course your window/session-id)
Code: Select all
qdbus org.kde.yakuake /Sessions/11 org.kde.konsole.Session.runCommand date
FlowXP
Registered Member
Posts
27
Karma
0
koffeinfriedhof wrote:Hi!

There is a runCommand-method in Konsole available via dbus. I'm using yakuake as dropdown-terminal, but it will work for konsole too if you replace yakuake with konsole-$id (and of course your window/session-id)
Code: Select all
qdbus org.kde.yakuake /Sessions/11 org.kde.konsole.Session.runCommand date


I have no idea how to use that, but after more digging and trying I found my answer :

Code: Select all
bash -c 'sleep 2 && echo "Sincronizez ! " && sync && sleep 2'


finally on KDE Neon !!
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
DBus is an interprocess communication system that allows you to trigger methods, connect and react to signals, ... It is worth a look.

Your solution will run without a visual feedback if you do not spawn a graphical terminal before running it. You could use Konsole to run such a command and keep the window open, e.g.
Code: Select all
konsole --hold -e 'bash -c "sync && echo finished...; sleep 2; echo Processing...; sleep 1; echo Done"'

This will hold the window open, even after 'echo Done' returns.

Another approach would be a logfile, or a notification after finishing sync. The && command only triggers if the process before it is returning without errors, so in your example the last 'sleep 2' would only trigger if sync is finished without error. Consider using a message on failure, for example
Code: Select all
sync || echo sync failed
FlowXP
Registered Member
Posts
27
Karma
0
I tried with this one in FreeFileSync after it finishes ... but nothing shows up.
Code: Select all
konsole --hold -e 'bash -c "sync && echo finished...; sleep 2; echo Processing...; sleep 1; echo Done"'


finally on KDE Neon !!
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
So FreeFileSync does trigger the command? Perhaps it is missing the $PATH or runs another shell interpreter. Try it with full path
Code: Select all
/usr/bin/konsole --hold -e 'echo Read this'

If it does not show up, check the logfiles of FreeFileSync or `journalctl -xe` for messages. I do not know FreeFileSync, so it is just an idea.
FlowXP
Registered Member
Posts
27
Karma
0
koffeinfriedhof wrote:So FreeFileSync does trigger the command? Perhaps it is missing the $PATH or runs another shell interpreter. Try it with full path
Code: Select all
/usr/bin/konsole --hold -e 'echo Read this'

If it does not show up, check the logfiles of FreeFileSync or `journalctl -xe` for messages. I do not know FreeFileSync, so it is just an idea.


yap ! that was it ! Thank you !!

so for me this is what I was searching for :
Code: Select all
/usr/bin/konsole -e 'bash -c "sync && echo Sync...; sleep 5"'


finally on KDE Neon !!
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
Great ;)

Now you could enhance it with a failcheck, like `sync || notify-send "Sync FAILED" "There was an error syncing, please check!"`. || is the opposite of &&, so instead of running on success of the previous process, it only runs if the previous process failed.
Have fun ;D
FlowXP
Registered Member
Posts
27
Karma
0
FlowXP wrote:
koffeinfriedhof wrote:So FreeFileSync does trigger the command? Perhaps it is missing the $PATH or runs another shell interpreter. Try it with full path
Code: Select all
/usr/bin/konsole --hold -e 'echo Read this'

If it does not show up, check the logfiles of FreeFileSync or `journalctl -xe` for messages. I do not know FreeFileSync, so it is just an idea.


yap ! that was it ! Thank you !!

so for me this is what I was searching for :
Code: Select all
/usr/bin/konsole -e 'bash -c "sync && echo Sync...; sleep 5"'



Ok so this doesn't work in qbittorrent, at the end of a download I made this
Code: Select all
/usr/bin/konsole --hold -e 'usr/bin/bash -c "sync && echo Sync...; sleep 3"'

and I get this :
Code: Select all
Warning: Could not find ''usr/bin/bash', starting '/bin/bash' instead.  Please check your profile settings.

/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file


I presume the problem is in my sintax ? It can't be because it's an appimage because it has acces to /usr/bin/konsole, but not to /usr/bin/bash ??


finally on KDE Neon !!
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
''usr/bin/bash' is missing the root-directory, you have to use an absolut path: /usr/bin/bash
FlowXP
Registered Member
Posts
27
Karma
0
nope,
it's the same
Code: Select all
Warning: Could not find ''/usr/bin/bash', starting '/bin/bash' instead.  Please check your profile settings.

/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file


finally on KDE Neon !!
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
Can you check the whole line again? There is missing an apostrophe. Is your bash located in /usr/bin/bash? try `which bash` or `type bash` to get the resolved absolute path.
FlowXP
Registered Member
Posts
27
Karma
0
It's there :
Code: Select all
$ which bash
/usr/bin/bash
$ type bash
bash is /usr/bin/bash


After lots of baby steps I discover the final form !! :

Code: Select all
/usr/bin/konsole -e bash -c "sync && echo Sync... && sleep 5"


Thank you again !


finally on KDE Neon !!
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]