Do GUI based application execute shell commands in the background?
up vote
29
down vote
favorite
I have migrated to Ubuntu 16.04 just 2 days ago from Windows. I like the way we can customise the Unity Desktop. I am just playing around with the look and feel of the Desktop environment. Just like in Windows, I wanted the launcher to be at the bottom of the screen. On Googling, I found a command which goes like:
gsettings set com.canonical.Unity.Launcher launcher-position Bottom
Also, there are the unity-tweak-tool and dconf editor to get the job done. But these are the GUI approach of getting things done.
My questions are:
- Do these GUI-based applications also execute the same command in the background?
- How to have a peep at the internal working of these applications? I mean, is there any way of actually looking at the commands that are being executed at every click of button?
- Do these applications open up a terminal in the background and execute these commands?
The answer here tells how to get the process's standard file descriptor. But, I did't get anything in the output.
Moreover, the strace -p pid -o output.txt
command throws a huge amount of text into the file.
So, in short, is doing things using GUI applications same as doing stuff from the commandline?
command-line unity launcher dconf gsettings
add a comment |
up vote
29
down vote
favorite
I have migrated to Ubuntu 16.04 just 2 days ago from Windows. I like the way we can customise the Unity Desktop. I am just playing around with the look and feel of the Desktop environment. Just like in Windows, I wanted the launcher to be at the bottom of the screen. On Googling, I found a command which goes like:
gsettings set com.canonical.Unity.Launcher launcher-position Bottom
Also, there are the unity-tweak-tool and dconf editor to get the job done. But these are the GUI approach of getting things done.
My questions are:
- Do these GUI-based applications also execute the same command in the background?
- How to have a peep at the internal working of these applications? I mean, is there any way of actually looking at the commands that are being executed at every click of button?
- Do these applications open up a terminal in the background and execute these commands?
The answer here tells how to get the process's standard file descriptor. But, I did't get anything in the output.
Moreover, the strace -p pid -o output.txt
command throws a huge amount of text into the file.
So, in short, is doing things using GUI applications same as doing stuff from the commandline?
command-line unity launcher dconf gsettings
add a comment |
up vote
29
down vote
favorite
up vote
29
down vote
favorite
I have migrated to Ubuntu 16.04 just 2 days ago from Windows. I like the way we can customise the Unity Desktop. I am just playing around with the look and feel of the Desktop environment. Just like in Windows, I wanted the launcher to be at the bottom of the screen. On Googling, I found a command which goes like:
gsettings set com.canonical.Unity.Launcher launcher-position Bottom
Also, there are the unity-tweak-tool and dconf editor to get the job done. But these are the GUI approach of getting things done.
My questions are:
- Do these GUI-based applications also execute the same command in the background?
- How to have a peep at the internal working of these applications? I mean, is there any way of actually looking at the commands that are being executed at every click of button?
- Do these applications open up a terminal in the background and execute these commands?
The answer here tells how to get the process's standard file descriptor. But, I did't get anything in the output.
Moreover, the strace -p pid -o output.txt
command throws a huge amount of text into the file.
So, in short, is doing things using GUI applications same as doing stuff from the commandline?
command-line unity launcher dconf gsettings
I have migrated to Ubuntu 16.04 just 2 days ago from Windows. I like the way we can customise the Unity Desktop. I am just playing around with the look and feel of the Desktop environment. Just like in Windows, I wanted the launcher to be at the bottom of the screen. On Googling, I found a command which goes like:
gsettings set com.canonical.Unity.Launcher launcher-position Bottom
Also, there are the unity-tweak-tool and dconf editor to get the job done. But these are the GUI approach of getting things done.
My questions are:
- Do these GUI-based applications also execute the same command in the background?
- How to have a peep at the internal working of these applications? I mean, is there any way of actually looking at the commands that are being executed at every click of button?
- Do these applications open up a terminal in the background and execute these commands?
The answer here tells how to get the process's standard file descriptor. But, I did't get anything in the output.
Moreover, the strace -p pid -o output.txt
command throws a huge amount of text into the file.
So, in short, is doing things using GUI applications same as doing stuff from the commandline?
command-line unity launcher dconf gsettings
command-line unity launcher dconf gsettings
edited Apr 13 '17 at 12:25
Community♦
1
1
asked Nov 14 '16 at 11:52
Logan
317318
317318
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
35
down vote
accepted
Do these GUI-based applications also execute the same command in the background?
Yes and no. They write to the dconf
database of settings, but they could be using different ways to do so. Programs written in Python will likely use the gi.repository.Gio
module (I know because I use it a lot) or they can instead use gsettings
as an external command by calling subprocess.Popen(['gsettings','org.some.schema','some-key','value'])
, and it will basically run as a shell command. A C program will use something similar, likely a gio.h
library, or it could even use the exec()
family of functions to do the same as Popen
does in python. So to answer your title question: "Do GUI based application execute shell commands in the background?" They can, but likely it's not necessary because there's a library for whatever language that app is written in, and likely it's gonna be a bit faster to use a library function, than spawning a new process.
To give you a sample of how it's done with libraries/modules, feel free to take a look at the source code of my launcher list indicator. There I have written a function to create an instance of the Gio.Settings
class and then use it to modify the Unity launcher depending on the type of list you want to have there.
How to have a peep at the internal working of these applications? I mean, is there any way of actually looking at the commands that are being executed at every click of button?
No. If you want to see which command is issued in that app's programming language as you press a button or click on window elements, then it's not possible. Read the source code of application, if it is possible to obtain it. You can use dconf watch /
to see what settings are being changed, but not how it's done.
Technically, if you know how to operate a debugger, read memory addresses, and know some assembly language, then you can know what an app does on the CPU and memory level. This is known as software reverse engineering and is frequently used by security professionals to analyze malicious software and discover vulnerabilities in legitimate software.
Do these applications open up a terminal in the background and execute these commands?
No, there's no terminal attached. Many programs know where the dconf
database for the user is located and write there. There's also an inter-process communication bus known as dbus
, where programs can send signals, and a program will be like "Hey, that's a message for me!"
Addendum
Can applications run other applications ? Yes, that's done via standard
fork()
andexecve()
system calls. The essence of creating processes on Linux and other *nix systems is largely based on these two. Shell mechanism for running non-builtin commands uses that a lot in particular. When you run interactively
$ ls
the shell will create a new process via
fork()
, that process will runexecve()
which will startls
. Because of howexecve()
that new forked process will bels
. Thepipe()
system call is what will help read back the output ofls
. I strongly suggest reading my answer for What is the difference between pipe and redirection to understand how pipe mechanism works - it's not just|
operator, but actually a syscall.
Can applications run shell commands ? No. Shell syntax is only understood by shell itself. What you can do, however, is start a shell with a command-line
-c
switch and provide appropriate commands. This is often used for custom shortcuts set in GNOME or other desktop environments, since custom shortcuts operate on executables and there is no shell to understand the syntax. Thus as an example, you'd dobash -c 'xdotool key Ctrl+Alt+T'
to indirectly runxdotool
command orbash -c 'cd $HOME/Desktop; touch New_File'
to create new file on desktop via shortcut. This is particularly interesting example as you can use a shell variable, since you are using a shell explicitly.
2
Thank you so much @Serg for the detailed explanation and answering each question separately and systematically!
– Logan
Nov 14 '16 at 14:03
@Logan my pleasure, always glad to help :)
– Sergiy Kolodyazhnyy
Nov 14 '16 at 14:26
1
Luckily, the source for the mentioned tools is available since they are FLOSS. Therefore I would say reversing them is a bit overkill in this case. :)
– Andrea Lazzarotto
Nov 15 '16 at 8:53
1
@AndreaLazzarotto Yep, Unity Tweak Tool and Dconf editor - those are open source, so there's no need to reverse engineer those. In my answer I kept everything very general and tried to cover not just those tools, but other possibilities
– Sergiy Kolodyazhnyy
Nov 15 '16 at 12:20
Faster is rarely the point for GUI applications. Escaping or marshalling the values for use with a shell tool is tedious, easy to get wrong and pointless if you can simply use the library. Re debugging: If the application is installed with debug symbols and written in a language supported by gdb (on debian e.g. by installing a corresponding -dbg package), you don’t need to know assembler: gdb will show you the source code using the debug info while you step through the application. What will be harder is to find a proper entry point to start debugging from, because of boring GUI boilerplate.
– Jonas Schäfer
Nov 15 '16 at 16:49
add a comment |
up vote
21
down vote
Spying on what happens
Most of what these settings editors do can be watched by running
dconf watch /
in a terminal.
gsettings
Also most of the time, to achieve what you see happening with the command above, these applications will need to edit the dconf
database (further below). This can be done either directly, by using the cli options of dconf (which is not preferred), or by running the corresponding gsettings
commands, like the one you mention.
To run these commands, no terminal window is needed, as you can see in the examples.
About, gsettings, dconf and the dconf database
gsettings
is the cli frontend to dconf
, which in its turn edits the dconf
database, where most of the settings are stored, in binary format. See also this nice answer.
The dconf
database, by the way, can also be edited from the GUI by dconf
editor, which is in the repositories:
Working samples
a. In python
To show you what happens under the hood, below a working sample to toggle your launcher position from GUI in a single (toggle) button:
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import subprocess
key = ["com.canonical.Unity.Launcher", "launcher-position"]
class ToggleWin(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Toggle")
button = Gtk.Button("Toggle launcherposition")
button.connect("clicked", self.toggle)
self.add(button)
def toggle(self, *args):
# read the current setting on launcher position
current = subprocess.check_output([
"gsettings", "get", key[0], key[1]
]).decode("utf-8").strip()
# toggle to the other option
new = "'Left'" if current == "'Bottom'" else "'Bottom'"
subprocess.Popen([
"gsettings", "set", key[0], key[1], new
])
def delete_actions(*args):
Gtk.main_quit()
def miniwindow():
window = ToggleWin()
window.connect("destroy", delete_actions)
window.show_all()
Gtk.main()
miniwindow()
- Paste the code into an empty
file.py
run it by the command:
python3 /path/to/file.py
...and have fun.
b. Launcher icon
Even a simple launcher can do the job from the GUI:
[Desktop Entry]
Name=Set launcherposition
Exec=zenity --info --text="Right- click to set launcher position"
Type=Application
StartupNotify=False
Icon=preferences-system
Actions=Launcher to bottom;Launcher on the left;
[Desktop Action Launcher to bottom]
Name=Launcher to bottom
# right click option to set launcher to bottom
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Bottom
[Desktop Action Launcher on the left]
Name=Launcher on the left
# right click option to set launcher to left
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Left
- Paste the code into an empty file, save it as
setlauncher.desktop
- Drag it on to the launcher and right-click
For permanent use, store it in ~/.local/share/applications
(for local use) or ~/usr/share/applications
for all users.
@Logan don't mention it :)
– Jacob Vlijm
Nov 14 '16 at 14:03
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f849304%2fdo-gui-based-application-execute-shell-commands-in-the-background%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
35
down vote
accepted
Do these GUI-based applications also execute the same command in the background?
Yes and no. They write to the dconf
database of settings, but they could be using different ways to do so. Programs written in Python will likely use the gi.repository.Gio
module (I know because I use it a lot) or they can instead use gsettings
as an external command by calling subprocess.Popen(['gsettings','org.some.schema','some-key','value'])
, and it will basically run as a shell command. A C program will use something similar, likely a gio.h
library, or it could even use the exec()
family of functions to do the same as Popen
does in python. So to answer your title question: "Do GUI based application execute shell commands in the background?" They can, but likely it's not necessary because there's a library for whatever language that app is written in, and likely it's gonna be a bit faster to use a library function, than spawning a new process.
To give you a sample of how it's done with libraries/modules, feel free to take a look at the source code of my launcher list indicator. There I have written a function to create an instance of the Gio.Settings
class and then use it to modify the Unity launcher depending on the type of list you want to have there.
How to have a peep at the internal working of these applications? I mean, is there any way of actually looking at the commands that are being executed at every click of button?
No. If you want to see which command is issued in that app's programming language as you press a button or click on window elements, then it's not possible. Read the source code of application, if it is possible to obtain it. You can use dconf watch /
to see what settings are being changed, but not how it's done.
Technically, if you know how to operate a debugger, read memory addresses, and know some assembly language, then you can know what an app does on the CPU and memory level. This is known as software reverse engineering and is frequently used by security professionals to analyze malicious software and discover vulnerabilities in legitimate software.
Do these applications open up a terminal in the background and execute these commands?
No, there's no terminal attached. Many programs know where the dconf
database for the user is located and write there. There's also an inter-process communication bus known as dbus
, where programs can send signals, and a program will be like "Hey, that's a message for me!"
Addendum
Can applications run other applications ? Yes, that's done via standard
fork()
andexecve()
system calls. The essence of creating processes on Linux and other *nix systems is largely based on these two. Shell mechanism for running non-builtin commands uses that a lot in particular. When you run interactively
$ ls
the shell will create a new process via
fork()
, that process will runexecve()
which will startls
. Because of howexecve()
that new forked process will bels
. Thepipe()
system call is what will help read back the output ofls
. I strongly suggest reading my answer for What is the difference between pipe and redirection to understand how pipe mechanism works - it's not just|
operator, but actually a syscall.
Can applications run shell commands ? No. Shell syntax is only understood by shell itself. What you can do, however, is start a shell with a command-line
-c
switch and provide appropriate commands. This is often used for custom shortcuts set in GNOME or other desktop environments, since custom shortcuts operate on executables and there is no shell to understand the syntax. Thus as an example, you'd dobash -c 'xdotool key Ctrl+Alt+T'
to indirectly runxdotool
command orbash -c 'cd $HOME/Desktop; touch New_File'
to create new file on desktop via shortcut. This is particularly interesting example as you can use a shell variable, since you are using a shell explicitly.
2
Thank you so much @Serg for the detailed explanation and answering each question separately and systematically!
– Logan
Nov 14 '16 at 14:03
@Logan my pleasure, always glad to help :)
– Sergiy Kolodyazhnyy
Nov 14 '16 at 14:26
1
Luckily, the source for the mentioned tools is available since they are FLOSS. Therefore I would say reversing them is a bit overkill in this case. :)
– Andrea Lazzarotto
Nov 15 '16 at 8:53
1
@AndreaLazzarotto Yep, Unity Tweak Tool and Dconf editor - those are open source, so there's no need to reverse engineer those. In my answer I kept everything very general and tried to cover not just those tools, but other possibilities
– Sergiy Kolodyazhnyy
Nov 15 '16 at 12:20
Faster is rarely the point for GUI applications. Escaping or marshalling the values for use with a shell tool is tedious, easy to get wrong and pointless if you can simply use the library. Re debugging: If the application is installed with debug symbols and written in a language supported by gdb (on debian e.g. by installing a corresponding -dbg package), you don’t need to know assembler: gdb will show you the source code using the debug info while you step through the application. What will be harder is to find a proper entry point to start debugging from, because of boring GUI boilerplate.
– Jonas Schäfer
Nov 15 '16 at 16:49
add a comment |
up vote
35
down vote
accepted
Do these GUI-based applications also execute the same command in the background?
Yes and no. They write to the dconf
database of settings, but they could be using different ways to do so. Programs written in Python will likely use the gi.repository.Gio
module (I know because I use it a lot) or they can instead use gsettings
as an external command by calling subprocess.Popen(['gsettings','org.some.schema','some-key','value'])
, and it will basically run as a shell command. A C program will use something similar, likely a gio.h
library, or it could even use the exec()
family of functions to do the same as Popen
does in python. So to answer your title question: "Do GUI based application execute shell commands in the background?" They can, but likely it's not necessary because there's a library for whatever language that app is written in, and likely it's gonna be a bit faster to use a library function, than spawning a new process.
To give you a sample of how it's done with libraries/modules, feel free to take a look at the source code of my launcher list indicator. There I have written a function to create an instance of the Gio.Settings
class and then use it to modify the Unity launcher depending on the type of list you want to have there.
How to have a peep at the internal working of these applications? I mean, is there any way of actually looking at the commands that are being executed at every click of button?
No. If you want to see which command is issued in that app's programming language as you press a button or click on window elements, then it's not possible. Read the source code of application, if it is possible to obtain it. You can use dconf watch /
to see what settings are being changed, but not how it's done.
Technically, if you know how to operate a debugger, read memory addresses, and know some assembly language, then you can know what an app does on the CPU and memory level. This is known as software reverse engineering and is frequently used by security professionals to analyze malicious software and discover vulnerabilities in legitimate software.
Do these applications open up a terminal in the background and execute these commands?
No, there's no terminal attached. Many programs know where the dconf
database for the user is located and write there. There's also an inter-process communication bus known as dbus
, where programs can send signals, and a program will be like "Hey, that's a message for me!"
Addendum
Can applications run other applications ? Yes, that's done via standard
fork()
andexecve()
system calls. The essence of creating processes on Linux and other *nix systems is largely based on these two. Shell mechanism for running non-builtin commands uses that a lot in particular. When you run interactively
$ ls
the shell will create a new process via
fork()
, that process will runexecve()
which will startls
. Because of howexecve()
that new forked process will bels
. Thepipe()
system call is what will help read back the output ofls
. I strongly suggest reading my answer for What is the difference between pipe and redirection to understand how pipe mechanism works - it's not just|
operator, but actually a syscall.
Can applications run shell commands ? No. Shell syntax is only understood by shell itself. What you can do, however, is start a shell with a command-line
-c
switch and provide appropriate commands. This is often used for custom shortcuts set in GNOME or other desktop environments, since custom shortcuts operate on executables and there is no shell to understand the syntax. Thus as an example, you'd dobash -c 'xdotool key Ctrl+Alt+T'
to indirectly runxdotool
command orbash -c 'cd $HOME/Desktop; touch New_File'
to create new file on desktop via shortcut. This is particularly interesting example as you can use a shell variable, since you are using a shell explicitly.
2
Thank you so much @Serg for the detailed explanation and answering each question separately and systematically!
– Logan
Nov 14 '16 at 14:03
@Logan my pleasure, always glad to help :)
– Sergiy Kolodyazhnyy
Nov 14 '16 at 14:26
1
Luckily, the source for the mentioned tools is available since they are FLOSS. Therefore I would say reversing them is a bit overkill in this case. :)
– Andrea Lazzarotto
Nov 15 '16 at 8:53
1
@AndreaLazzarotto Yep, Unity Tweak Tool and Dconf editor - those are open source, so there's no need to reverse engineer those. In my answer I kept everything very general and tried to cover not just those tools, but other possibilities
– Sergiy Kolodyazhnyy
Nov 15 '16 at 12:20
Faster is rarely the point for GUI applications. Escaping or marshalling the values for use with a shell tool is tedious, easy to get wrong and pointless if you can simply use the library. Re debugging: If the application is installed with debug symbols and written in a language supported by gdb (on debian e.g. by installing a corresponding -dbg package), you don’t need to know assembler: gdb will show you the source code using the debug info while you step through the application. What will be harder is to find a proper entry point to start debugging from, because of boring GUI boilerplate.
– Jonas Schäfer
Nov 15 '16 at 16:49
add a comment |
up vote
35
down vote
accepted
up vote
35
down vote
accepted
Do these GUI-based applications also execute the same command in the background?
Yes and no. They write to the dconf
database of settings, but they could be using different ways to do so. Programs written in Python will likely use the gi.repository.Gio
module (I know because I use it a lot) or they can instead use gsettings
as an external command by calling subprocess.Popen(['gsettings','org.some.schema','some-key','value'])
, and it will basically run as a shell command. A C program will use something similar, likely a gio.h
library, or it could even use the exec()
family of functions to do the same as Popen
does in python. So to answer your title question: "Do GUI based application execute shell commands in the background?" They can, but likely it's not necessary because there's a library for whatever language that app is written in, and likely it's gonna be a bit faster to use a library function, than spawning a new process.
To give you a sample of how it's done with libraries/modules, feel free to take a look at the source code of my launcher list indicator. There I have written a function to create an instance of the Gio.Settings
class and then use it to modify the Unity launcher depending on the type of list you want to have there.
How to have a peep at the internal working of these applications? I mean, is there any way of actually looking at the commands that are being executed at every click of button?
No. If you want to see which command is issued in that app's programming language as you press a button or click on window elements, then it's not possible. Read the source code of application, if it is possible to obtain it. You can use dconf watch /
to see what settings are being changed, but not how it's done.
Technically, if you know how to operate a debugger, read memory addresses, and know some assembly language, then you can know what an app does on the CPU and memory level. This is known as software reverse engineering and is frequently used by security professionals to analyze malicious software and discover vulnerabilities in legitimate software.
Do these applications open up a terminal in the background and execute these commands?
No, there's no terminal attached. Many programs know where the dconf
database for the user is located and write there. There's also an inter-process communication bus known as dbus
, where programs can send signals, and a program will be like "Hey, that's a message for me!"
Addendum
Can applications run other applications ? Yes, that's done via standard
fork()
andexecve()
system calls. The essence of creating processes on Linux and other *nix systems is largely based on these two. Shell mechanism for running non-builtin commands uses that a lot in particular. When you run interactively
$ ls
the shell will create a new process via
fork()
, that process will runexecve()
which will startls
. Because of howexecve()
that new forked process will bels
. Thepipe()
system call is what will help read back the output ofls
. I strongly suggest reading my answer for What is the difference between pipe and redirection to understand how pipe mechanism works - it's not just|
operator, but actually a syscall.
Can applications run shell commands ? No. Shell syntax is only understood by shell itself. What you can do, however, is start a shell with a command-line
-c
switch and provide appropriate commands. This is often used for custom shortcuts set in GNOME or other desktop environments, since custom shortcuts operate on executables and there is no shell to understand the syntax. Thus as an example, you'd dobash -c 'xdotool key Ctrl+Alt+T'
to indirectly runxdotool
command orbash -c 'cd $HOME/Desktop; touch New_File'
to create new file on desktop via shortcut. This is particularly interesting example as you can use a shell variable, since you are using a shell explicitly.
Do these GUI-based applications also execute the same command in the background?
Yes and no. They write to the dconf
database of settings, but they could be using different ways to do so. Programs written in Python will likely use the gi.repository.Gio
module (I know because I use it a lot) or they can instead use gsettings
as an external command by calling subprocess.Popen(['gsettings','org.some.schema','some-key','value'])
, and it will basically run as a shell command. A C program will use something similar, likely a gio.h
library, or it could even use the exec()
family of functions to do the same as Popen
does in python. So to answer your title question: "Do GUI based application execute shell commands in the background?" They can, but likely it's not necessary because there's a library for whatever language that app is written in, and likely it's gonna be a bit faster to use a library function, than spawning a new process.
To give you a sample of how it's done with libraries/modules, feel free to take a look at the source code of my launcher list indicator. There I have written a function to create an instance of the Gio.Settings
class and then use it to modify the Unity launcher depending on the type of list you want to have there.
How to have a peep at the internal working of these applications? I mean, is there any way of actually looking at the commands that are being executed at every click of button?
No. If you want to see which command is issued in that app's programming language as you press a button or click on window elements, then it's not possible. Read the source code of application, if it is possible to obtain it. You can use dconf watch /
to see what settings are being changed, but not how it's done.
Technically, if you know how to operate a debugger, read memory addresses, and know some assembly language, then you can know what an app does on the CPU and memory level. This is known as software reverse engineering and is frequently used by security professionals to analyze malicious software and discover vulnerabilities in legitimate software.
Do these applications open up a terminal in the background and execute these commands?
No, there's no terminal attached. Many programs know where the dconf
database for the user is located and write there. There's also an inter-process communication bus known as dbus
, where programs can send signals, and a program will be like "Hey, that's a message for me!"
Addendum
Can applications run other applications ? Yes, that's done via standard
fork()
andexecve()
system calls. The essence of creating processes on Linux and other *nix systems is largely based on these two. Shell mechanism for running non-builtin commands uses that a lot in particular. When you run interactively
$ ls
the shell will create a new process via
fork()
, that process will runexecve()
which will startls
. Because of howexecve()
that new forked process will bels
. Thepipe()
system call is what will help read back the output ofls
. I strongly suggest reading my answer for What is the difference between pipe and redirection to understand how pipe mechanism works - it's not just|
operator, but actually a syscall.
Can applications run shell commands ? No. Shell syntax is only understood by shell itself. What you can do, however, is start a shell with a command-line
-c
switch and provide appropriate commands. This is often used for custom shortcuts set in GNOME or other desktop environments, since custom shortcuts operate on executables and there is no shell to understand the syntax. Thus as an example, you'd dobash -c 'xdotool key Ctrl+Alt+T'
to indirectly runxdotool
command orbash -c 'cd $HOME/Desktop; touch New_File'
to create new file on desktop via shortcut. This is particularly interesting example as you can use a shell variable, since you are using a shell explicitly.
edited Dec 10 at 3:59
answered Nov 14 '16 at 12:04
Sergiy Kolodyazhnyy
68.9k9143303
68.9k9143303
2
Thank you so much @Serg for the detailed explanation and answering each question separately and systematically!
– Logan
Nov 14 '16 at 14:03
@Logan my pleasure, always glad to help :)
– Sergiy Kolodyazhnyy
Nov 14 '16 at 14:26
1
Luckily, the source for the mentioned tools is available since they are FLOSS. Therefore I would say reversing them is a bit overkill in this case. :)
– Andrea Lazzarotto
Nov 15 '16 at 8:53
1
@AndreaLazzarotto Yep, Unity Tweak Tool and Dconf editor - those are open source, so there's no need to reverse engineer those. In my answer I kept everything very general and tried to cover not just those tools, but other possibilities
– Sergiy Kolodyazhnyy
Nov 15 '16 at 12:20
Faster is rarely the point for GUI applications. Escaping or marshalling the values for use with a shell tool is tedious, easy to get wrong and pointless if you can simply use the library. Re debugging: If the application is installed with debug symbols and written in a language supported by gdb (on debian e.g. by installing a corresponding -dbg package), you don’t need to know assembler: gdb will show you the source code using the debug info while you step through the application. What will be harder is to find a proper entry point to start debugging from, because of boring GUI boilerplate.
– Jonas Schäfer
Nov 15 '16 at 16:49
add a comment |
2
Thank you so much @Serg for the detailed explanation and answering each question separately and systematically!
– Logan
Nov 14 '16 at 14:03
@Logan my pleasure, always glad to help :)
– Sergiy Kolodyazhnyy
Nov 14 '16 at 14:26
1
Luckily, the source for the mentioned tools is available since they are FLOSS. Therefore I would say reversing them is a bit overkill in this case. :)
– Andrea Lazzarotto
Nov 15 '16 at 8:53
1
@AndreaLazzarotto Yep, Unity Tweak Tool and Dconf editor - those are open source, so there's no need to reverse engineer those. In my answer I kept everything very general and tried to cover not just those tools, but other possibilities
– Sergiy Kolodyazhnyy
Nov 15 '16 at 12:20
Faster is rarely the point for GUI applications. Escaping or marshalling the values for use with a shell tool is tedious, easy to get wrong and pointless if you can simply use the library. Re debugging: If the application is installed with debug symbols and written in a language supported by gdb (on debian e.g. by installing a corresponding -dbg package), you don’t need to know assembler: gdb will show you the source code using the debug info while you step through the application. What will be harder is to find a proper entry point to start debugging from, because of boring GUI boilerplate.
– Jonas Schäfer
Nov 15 '16 at 16:49
2
2
Thank you so much @Serg for the detailed explanation and answering each question separately and systematically!
– Logan
Nov 14 '16 at 14:03
Thank you so much @Serg for the detailed explanation and answering each question separately and systematically!
– Logan
Nov 14 '16 at 14:03
@Logan my pleasure, always glad to help :)
– Sergiy Kolodyazhnyy
Nov 14 '16 at 14:26
@Logan my pleasure, always glad to help :)
– Sergiy Kolodyazhnyy
Nov 14 '16 at 14:26
1
1
Luckily, the source for the mentioned tools is available since they are FLOSS. Therefore I would say reversing them is a bit overkill in this case. :)
– Andrea Lazzarotto
Nov 15 '16 at 8:53
Luckily, the source for the mentioned tools is available since they are FLOSS. Therefore I would say reversing them is a bit overkill in this case. :)
– Andrea Lazzarotto
Nov 15 '16 at 8:53
1
1
@AndreaLazzarotto Yep, Unity Tweak Tool and Dconf editor - those are open source, so there's no need to reverse engineer those. In my answer I kept everything very general and tried to cover not just those tools, but other possibilities
– Sergiy Kolodyazhnyy
Nov 15 '16 at 12:20
@AndreaLazzarotto Yep, Unity Tweak Tool and Dconf editor - those are open source, so there's no need to reverse engineer those. In my answer I kept everything very general and tried to cover not just those tools, but other possibilities
– Sergiy Kolodyazhnyy
Nov 15 '16 at 12:20
Faster is rarely the point for GUI applications. Escaping or marshalling the values for use with a shell tool is tedious, easy to get wrong and pointless if you can simply use the library. Re debugging: If the application is installed with debug symbols and written in a language supported by gdb (on debian e.g. by installing a corresponding -dbg package), you don’t need to know assembler: gdb will show you the source code using the debug info while you step through the application. What will be harder is to find a proper entry point to start debugging from, because of boring GUI boilerplate.
– Jonas Schäfer
Nov 15 '16 at 16:49
Faster is rarely the point for GUI applications. Escaping or marshalling the values for use with a shell tool is tedious, easy to get wrong and pointless if you can simply use the library. Re debugging: If the application is installed with debug symbols and written in a language supported by gdb (on debian e.g. by installing a corresponding -dbg package), you don’t need to know assembler: gdb will show you the source code using the debug info while you step through the application. What will be harder is to find a proper entry point to start debugging from, because of boring GUI boilerplate.
– Jonas Schäfer
Nov 15 '16 at 16:49
add a comment |
up vote
21
down vote
Spying on what happens
Most of what these settings editors do can be watched by running
dconf watch /
in a terminal.
gsettings
Also most of the time, to achieve what you see happening with the command above, these applications will need to edit the dconf
database (further below). This can be done either directly, by using the cli options of dconf (which is not preferred), or by running the corresponding gsettings
commands, like the one you mention.
To run these commands, no terminal window is needed, as you can see in the examples.
About, gsettings, dconf and the dconf database
gsettings
is the cli frontend to dconf
, which in its turn edits the dconf
database, where most of the settings are stored, in binary format. See also this nice answer.
The dconf
database, by the way, can also be edited from the GUI by dconf
editor, which is in the repositories:
Working samples
a. In python
To show you what happens under the hood, below a working sample to toggle your launcher position from GUI in a single (toggle) button:
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import subprocess
key = ["com.canonical.Unity.Launcher", "launcher-position"]
class ToggleWin(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Toggle")
button = Gtk.Button("Toggle launcherposition")
button.connect("clicked", self.toggle)
self.add(button)
def toggle(self, *args):
# read the current setting on launcher position
current = subprocess.check_output([
"gsettings", "get", key[0], key[1]
]).decode("utf-8").strip()
# toggle to the other option
new = "'Left'" if current == "'Bottom'" else "'Bottom'"
subprocess.Popen([
"gsettings", "set", key[0], key[1], new
])
def delete_actions(*args):
Gtk.main_quit()
def miniwindow():
window = ToggleWin()
window.connect("destroy", delete_actions)
window.show_all()
Gtk.main()
miniwindow()
- Paste the code into an empty
file.py
run it by the command:
python3 /path/to/file.py
...and have fun.
b. Launcher icon
Even a simple launcher can do the job from the GUI:
[Desktop Entry]
Name=Set launcherposition
Exec=zenity --info --text="Right- click to set launcher position"
Type=Application
StartupNotify=False
Icon=preferences-system
Actions=Launcher to bottom;Launcher on the left;
[Desktop Action Launcher to bottom]
Name=Launcher to bottom
# right click option to set launcher to bottom
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Bottom
[Desktop Action Launcher on the left]
Name=Launcher on the left
# right click option to set launcher to left
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Left
- Paste the code into an empty file, save it as
setlauncher.desktop
- Drag it on to the launcher and right-click
For permanent use, store it in ~/.local/share/applications
(for local use) or ~/usr/share/applications
for all users.
@Logan don't mention it :)
– Jacob Vlijm
Nov 14 '16 at 14:03
add a comment |
up vote
21
down vote
Spying on what happens
Most of what these settings editors do can be watched by running
dconf watch /
in a terminal.
gsettings
Also most of the time, to achieve what you see happening with the command above, these applications will need to edit the dconf
database (further below). This can be done either directly, by using the cli options of dconf (which is not preferred), or by running the corresponding gsettings
commands, like the one you mention.
To run these commands, no terminal window is needed, as you can see in the examples.
About, gsettings, dconf and the dconf database
gsettings
is the cli frontend to dconf
, which in its turn edits the dconf
database, where most of the settings are stored, in binary format. See also this nice answer.
The dconf
database, by the way, can also be edited from the GUI by dconf
editor, which is in the repositories:
Working samples
a. In python
To show you what happens under the hood, below a working sample to toggle your launcher position from GUI in a single (toggle) button:
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import subprocess
key = ["com.canonical.Unity.Launcher", "launcher-position"]
class ToggleWin(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Toggle")
button = Gtk.Button("Toggle launcherposition")
button.connect("clicked", self.toggle)
self.add(button)
def toggle(self, *args):
# read the current setting on launcher position
current = subprocess.check_output([
"gsettings", "get", key[0], key[1]
]).decode("utf-8").strip()
# toggle to the other option
new = "'Left'" if current == "'Bottom'" else "'Bottom'"
subprocess.Popen([
"gsettings", "set", key[0], key[1], new
])
def delete_actions(*args):
Gtk.main_quit()
def miniwindow():
window = ToggleWin()
window.connect("destroy", delete_actions)
window.show_all()
Gtk.main()
miniwindow()
- Paste the code into an empty
file.py
run it by the command:
python3 /path/to/file.py
...and have fun.
b. Launcher icon
Even a simple launcher can do the job from the GUI:
[Desktop Entry]
Name=Set launcherposition
Exec=zenity --info --text="Right- click to set launcher position"
Type=Application
StartupNotify=False
Icon=preferences-system
Actions=Launcher to bottom;Launcher on the left;
[Desktop Action Launcher to bottom]
Name=Launcher to bottom
# right click option to set launcher to bottom
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Bottom
[Desktop Action Launcher on the left]
Name=Launcher on the left
# right click option to set launcher to left
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Left
- Paste the code into an empty file, save it as
setlauncher.desktop
- Drag it on to the launcher and right-click
For permanent use, store it in ~/.local/share/applications
(for local use) or ~/usr/share/applications
for all users.
@Logan don't mention it :)
– Jacob Vlijm
Nov 14 '16 at 14:03
add a comment |
up vote
21
down vote
up vote
21
down vote
Spying on what happens
Most of what these settings editors do can be watched by running
dconf watch /
in a terminal.
gsettings
Also most of the time, to achieve what you see happening with the command above, these applications will need to edit the dconf
database (further below). This can be done either directly, by using the cli options of dconf (which is not preferred), or by running the corresponding gsettings
commands, like the one you mention.
To run these commands, no terminal window is needed, as you can see in the examples.
About, gsettings, dconf and the dconf database
gsettings
is the cli frontend to dconf
, which in its turn edits the dconf
database, where most of the settings are stored, in binary format. See also this nice answer.
The dconf
database, by the way, can also be edited from the GUI by dconf
editor, which is in the repositories:
Working samples
a. In python
To show you what happens under the hood, below a working sample to toggle your launcher position from GUI in a single (toggle) button:
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import subprocess
key = ["com.canonical.Unity.Launcher", "launcher-position"]
class ToggleWin(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Toggle")
button = Gtk.Button("Toggle launcherposition")
button.connect("clicked", self.toggle)
self.add(button)
def toggle(self, *args):
# read the current setting on launcher position
current = subprocess.check_output([
"gsettings", "get", key[0], key[1]
]).decode("utf-8").strip()
# toggle to the other option
new = "'Left'" if current == "'Bottom'" else "'Bottom'"
subprocess.Popen([
"gsettings", "set", key[0], key[1], new
])
def delete_actions(*args):
Gtk.main_quit()
def miniwindow():
window = ToggleWin()
window.connect("destroy", delete_actions)
window.show_all()
Gtk.main()
miniwindow()
- Paste the code into an empty
file.py
run it by the command:
python3 /path/to/file.py
...and have fun.
b. Launcher icon
Even a simple launcher can do the job from the GUI:
[Desktop Entry]
Name=Set launcherposition
Exec=zenity --info --text="Right- click to set launcher position"
Type=Application
StartupNotify=False
Icon=preferences-system
Actions=Launcher to bottom;Launcher on the left;
[Desktop Action Launcher to bottom]
Name=Launcher to bottom
# right click option to set launcher to bottom
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Bottom
[Desktop Action Launcher on the left]
Name=Launcher on the left
# right click option to set launcher to left
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Left
- Paste the code into an empty file, save it as
setlauncher.desktop
- Drag it on to the launcher and right-click
For permanent use, store it in ~/.local/share/applications
(for local use) or ~/usr/share/applications
for all users.
Spying on what happens
Most of what these settings editors do can be watched by running
dconf watch /
in a terminal.
gsettings
Also most of the time, to achieve what you see happening with the command above, these applications will need to edit the dconf
database (further below). This can be done either directly, by using the cli options of dconf (which is not preferred), or by running the corresponding gsettings
commands, like the one you mention.
To run these commands, no terminal window is needed, as you can see in the examples.
About, gsettings, dconf and the dconf database
gsettings
is the cli frontend to dconf
, which in its turn edits the dconf
database, where most of the settings are stored, in binary format. See also this nice answer.
The dconf
database, by the way, can also be edited from the GUI by dconf
editor, which is in the repositories:
Working samples
a. In python
To show you what happens under the hood, below a working sample to toggle your launcher position from GUI in a single (toggle) button:
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import subprocess
key = ["com.canonical.Unity.Launcher", "launcher-position"]
class ToggleWin(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Toggle")
button = Gtk.Button("Toggle launcherposition")
button.connect("clicked", self.toggle)
self.add(button)
def toggle(self, *args):
# read the current setting on launcher position
current = subprocess.check_output([
"gsettings", "get", key[0], key[1]
]).decode("utf-8").strip()
# toggle to the other option
new = "'Left'" if current == "'Bottom'" else "'Bottom'"
subprocess.Popen([
"gsettings", "set", key[0], key[1], new
])
def delete_actions(*args):
Gtk.main_quit()
def miniwindow():
window = ToggleWin()
window.connect("destroy", delete_actions)
window.show_all()
Gtk.main()
miniwindow()
- Paste the code into an empty
file.py
run it by the command:
python3 /path/to/file.py
...and have fun.
b. Launcher icon
Even a simple launcher can do the job from the GUI:
[Desktop Entry]
Name=Set launcherposition
Exec=zenity --info --text="Right- click to set launcher position"
Type=Application
StartupNotify=False
Icon=preferences-system
Actions=Launcher to bottom;Launcher on the left;
[Desktop Action Launcher to bottom]
Name=Launcher to bottom
# right click option to set launcher to bottom
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Bottom
[Desktop Action Launcher on the left]
Name=Launcher on the left
# right click option to set launcher to left
Exec=gsettings set com.canonical.Unity.Launcher launcher-position Left
- Paste the code into an empty file, save it as
setlauncher.desktop
- Drag it on to the launcher and right-click
For permanent use, store it in ~/.local/share/applications
(for local use) or ~/usr/share/applications
for all users.
edited Apr 13 '17 at 12:24
Community♦
1
1
answered Nov 14 '16 at 11:56
Jacob Vlijm
63.3k9122216
63.3k9122216
@Logan don't mention it :)
– Jacob Vlijm
Nov 14 '16 at 14:03
add a comment |
@Logan don't mention it :)
– Jacob Vlijm
Nov 14 '16 at 14:03
@Logan don't mention it :)
– Jacob Vlijm
Nov 14 '16 at 14:03
@Logan don't mention it :)
– Jacob Vlijm
Nov 14 '16 at 14:03
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f849304%2fdo-gui-based-application-execute-shell-commands-in-the-background%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown