Bug 238817 - Executing Plasma Desktop Scripts within a bash script
Summary: Executing Plasma Desktop Scripts within a bash script
Status: RESOLVED UNMAINTAINED
Alias: None
Product: plasma4
Classification: Plasma
Component: scriptengines (show other bugs)
Version: unspecified
Platform: Arch Linux Linux
: NOR wishlist
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-25 20:38 UTC by flasher.d84
Modified: 2018-06-08 20:03 UTC (History)
23 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description flasher.d84 2010-05-25 20:38:24 UTC
Version:           unspecified (using KDE 4.4.3) 
OS:                Linux

It isn't possible to execute a Plasma Desktop Script at each login within a bash script.

For example:
If you want to resize your panels each login dependent on you monitor setup (for example a Laptop with a docking station and dual monitor setup) I can't use the PlasmaDesktop Scripts (as described here: http://techbase.kde.org/KDE_System_Administration/PlasmaDesktopScripting) because there are only the possibilities to run it once or interactively.

For more information look at this topic at kde forum:
http://forum.kde.org/viewtopic.php?f=67&t=88100

Reproducible: Always
Comment 1 Maxim 2011-10-11 14:49:39 UTC
This also applies to me. I have to make some adjustments on screen resolution change. These adjustments can be made only through Plasma Desktop Script.

The thing is that I change resolution several times during my work (laptop + external monitors) and it's very inconvenient to run interactive console each time and execute a script.

Are there any limitations on running Plasma scripts from Shell?
Comment 2 Mikiya Okuno 2011-10-26 16:34:51 UTC
I like to have this feature. Calling a custom script from a command line can be really exciting. If you have a security concern, I suggest to limit scripts to run which are located under a certain directory where only the root can write such as `kde4-config --path data`/plasma-desktop/custom-scripts or similar.
Comment 3 Maxim 2011-10-26 16:56:48 UTC
Actually I was thinking about security, but don't see any issue here:

As far as I know, the only things that can be affected by such script are related to user settings. All users settings are stored in his home directory and ordinary shell scripts have access to this directory as well.

What I mean is that if a plasma script is executed from Shell it can't make more destrcutions than the same shell script can.

Anyway there are already plasma scripts exist which are executed automatically on startup or update. Executing a script from Shell can't be more dangerous
Comment 4 webcd 2011-12-15 16:38:50 UTC
*** This bug has been confirmed by popular vote. ***
Comment 5 webcd 2011-12-15 23:03:02 UTC
(In reply to comment #4)
> *** This bug has been confirmed by popular vote. ***

This would possibly FIX this bug:

kdebase-workspace/plasma/desktop/shell/plasmaapp.cpp

#include "scripting/scriptengine.h"

void PlasmaApp::runScript(const QString &script)
{
        ScriptEngine scriptEngine(this);
        connect(&scriptEngine, SIGNAL(printError(QString)), this, SLOT(printScriptError(QString)));
        connect(&scriptEngine, SIGNAL(print(QString)), this, SLOT(printScriptMessage(QString)));

        QFile file(script);
        if (file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
            QString code = file.readAll();
            kDebug() << "evaluating DBUS-run script:" << script;
            scriptEngine.evaluateScript(code);
        }
}

void PlasmaApp::printScriptError(const QString &error)
{
    /**TODO: send via DBUS */
    kWarning() << "Startup script errror:" << error;
}

void PlasmaApp::printScriptMessage(const QString &error)
{
    /**TODO: send via DBUS */
    kDebug() << "Startup script: " << error;
}

kdebase-workspace/plasma/desktop/shell/plasmaapp.h

public Q_SLOTS:
    void runScript(const QString &script);
private Q_SLOTS:
    void printScriptError(const QString &error)
    void printScriptMessage(const QString &error);
Comment 6 Jason Alavaliant 2013-05-29 06:45:36 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > *** This bug has been confirmed by popular vote. ***
> 
> This would possibly FIX this bug:
> 
> kdebase-workspace/plasma/desktop/shell/plasmaapp.cpp
> 
> #include "scripting/scriptengine.h"
> 
> void PlasmaApp::runScript(const QString &script)
> {
>         ScriptEngine scriptEngine(this);
>         connect(&scriptEngine, SIGNAL(printError(QString)), this,
> SLOT(printScriptError(QString)));
>         connect(&scriptEngine, SIGNAL(print(QString)), this,
> SLOT(printScriptMessage(QString)));
> 
>         QFile file(script);
>         if (file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
>             QString code = file.readAll();
>             kDebug() << "evaluating DBUS-run script:" << script;
>             scriptEngine.evaluateScript(code);
>         }
> }
> 
> void PlasmaApp::printScriptError(const QString &error)
> {
>     /**TODO: send via DBUS */
>     kWarning() << "Startup script errror:" << error;
> }
> 
> void PlasmaApp::printScriptMessage(const QString &error)
> {
>     /**TODO: send via DBUS */
>     kDebug() << "Startup script: " << error;
> }
> 
> kdebase-workspace/plasma/desktop/shell/plasmaapp.h
> 
> public Q_SLOTS:
>     void runScript(const QString &script);
> private Q_SLOTS:
>     void printScriptError(const QString &error)
>     void printScriptMessage(const QString &error);


I've been trying to build plasma-workspace with this patch to try it out but my builds all fail with 

[ 76%] Building CXX object plasma/desktop/shell/CMakeFiles/kdeinit_plasma-desktop.dir/plasmaapp.o
cd plasma/desktop/shell && /usr/bin/c++   -Dkdeinit_plasma_desktop_EXPORTS -D_BSD_SOURCE -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -DQT_NO_STL -DQT_NO_CAST_TO_ASCII -D_REENTRANT -DKDE_DEPRECATED_WARNINGS -DKDE4_CMAKE_TOPLEVEL_DIR_LENGTH=39 -DHAVE_CONFIG_H=1 -DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS -DDISABLE_NEPOMUK_LEGACY -DKDE_DEFAULT_DEBUG_AREA=1204 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security  -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -DQT_NO_EXCEPTIONS -fno-check-new -fno-common -Woverloaded-virtual -fno-threadsafe-statics -fvisibility=hidden -Werror=return-type -fvisibility-inlines-hidden -DNDEBUG -DQT_NO_DEBUG -fPIC -I. -I../../../../plasma/desktop/shell -I../../../.. -I../../.. -I../../../../libs -I../../../../libs/plasmagenericshell -I../../../../plasma/desktop/shell/scripting -I../../../../libs/kephal -I/usr/include/KDE -I/usr/include/qt4/phonon -I/usr/include/qt4/QtXmlPatterns -I/usr/include/qt4/QtXml -I/usr/include/qt4/QtWebKit -I/usr/include/qt4/QtUiTools -I/usr/include/qt4/QtTest -I/usr/include/qt4/QtSvg -I/usr/include/qt4/QtSql -I/usr/include/qt4/QtScriptTools -I/usr/include/qt4/QtScript -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtHelp -I/usr/include/qt4/QtDesigner -I/usr/include/qt4/QtDeclarative -I/usr/include/qt4/QtDBus -I/usr/include/qt4/Qt3Support -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtCore -I/usr/include/qt4/Qt -I/usr/share/qt4/mkspecs/default -I/usr/include/qt4    -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -o CMakeFiles/kdeinit_plasma-desktop.dir/plasmaapp.o -c ../../../../plasma/desktop/shell/plasmaapp.cpp
In file included from /usr/include/qt4/QtScript/qscriptengine.h:39:0,
                 from /usr/include/qt4/QtScript/QScriptEngine:1,
                 from ../../../../libs/plasmagenericshell/scripting/scriptengine.h:23,
                 from ../../../../plasma/desktop/shell/plasmaapp.cpp:102:
/usr/include/qt4/QtScript/qscriptcontext.h:43:9: error: expected identifier before numeric constant
/usr/include/qt4/QtScript/qscriptcontext.h:43:9: error: expected ‘}’ before numeric constant
/usr/include/qt4/QtScript/qscriptcontext.h:43:9: error: expected unqualified-id before numeric constant
/usr/include/qt4/QtScript/qscriptcontext.h:56:22: error: expected constructor, destructor, or type conversion before ‘;’ token
/usr/include/qt4/QtScript/qscriptcontext.h:58:37: error: non-member function ‘QScriptContext* parentContext()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:59:29: error: non-member function ‘QScriptEngine* engine()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:61:5: error: ‘ExecutionState’ does not name a type
/usr/include/qt4/QtScript/qscriptcontext.h:62:27: error: non-member function ‘QScriptValue callee()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:64:25: error: non-member function ‘int argumentCount()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:65:38: error: non-member function ‘QScriptValue argument(int)’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:66:36: error: non-member function ‘QScriptValue argumentsObject()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:68:35: error: non-member function ‘QScriptValueList scopeChain()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:72:32: error: non-member function ‘QScriptValue returnValue()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:75:37: error: non-member function ‘QScriptValue activationObject()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:78:31: error: non-member function ‘QScriptValue thisObject()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:81:34: error: non-member function ‘bool isCalledAsConstructor()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:87:29: error: non-member function ‘QStringList backtrace()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:89:24: error: non-member function ‘QString toString()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h:91:1: error: expected unqualified-id before ‘private’
/usr/include/qt4/QtScript/qscriptcontext.h:96:5: error: non-member function ‘const QScriptContextPrivate* d_func()’ cannot have cv-qualifier
/usr/include/qt4/QtScript/qscriptcontext.h: In function ‘const QScriptContextPrivate* d_func()’:
/usr/include/qt4/QtScript/qscriptcontext.h:96:5: error: new declaration ‘const QScriptContextPrivate* d_func()’
/usr/include/qt4/QtScript/qscriptcontext.h:96:5: error: ambiguates old declaration ‘QScriptContextPrivate* d_func()’
/usr/include/qt4/QtScript/qscriptcontext.h: At global scope:
/usr/include/qt4/QtScript/qscriptcontext.h:96:5: error: ‘friend’ used outside of class
/usr/include/qt4/QtScript/qscriptcontext.h:97:5: error: expected unqualified-id before ‘const’
/usr/include/qt4/QtScript/qscriptcontext.h:97:5: error: expected ‘)’ before ‘const’
/usr/include/qt4/QtScript/qscriptcontext.h:97:5: error: ‘QScriptContext& operator=(const QScriptContext&)’ must be a nonstatic member function
/usr/include/qt4/QtScript/qscriptcontext.h:98:1: error: expected declaration before ‘}’ token
make[5]: *** [plasma/desktop/shell/CMakeFiles/kdeinit_plasma-desktop.dir/plasmaapp.o] Error 1

Is there an updated version of this patch out there?
Comment 7 kYuZz 2014-02-27 13:52:18 UTC
I'd love to have this bug fixed too.
Comment 8 jhoo 2014-07-30 06:37:48 UTC
+1, please fix.
Comment 9 Luc 2014-12-20 15:11:16 UTC
+1 please...
Comment 10 s 2015-01-13 11:44:34 UTC
+1, it would be great for other very active projects like "variety" that this gets fixed
Comment 11 LordKhael Light 2015-06-27 16:46:35 UTC
*** Bug 349663 has been marked as a duplicate of this bug. ***
Comment 12 David Edmundson 2015-06-27 17:02:49 UTC
As the wiki says:

Just run

qdbus org.kde.plasma-desktop /MainApplication loadScriptInInteractiveConsole /path/to/file

?
Comment 13 andreas 2015-06-27 20:19:18 UTC
(In reply to David Edmundson from comment #12)
> As the wiki says:
> 
> Just run
> 
> qdbus org.kde.plasma-desktop /MainApplication loadScriptInInteractiveConsole
> /path/to/file
> 
> ?

That just opens the Scripting Console and loads the file but doesn't execute it.
Comment 14 Stefano Forli 2015-11-28 22:32:28 UTC
I can't tell how surprised and disappointed I was when I found this.
This is against the core of the KDE philosophy as I interpret it. 

Honestly, I'm struggling trying to figure out not only why this feature hasn't been added yet, but why it wasn't in to begin with. It seems that this extremely valuable feature was relegated only into events independent of the users (i.e., start-up, update).

Well, *bump*, I guess, while they figure out what to do with this.
Comment 15 noric 2016-01-15 00:03:08 UTC
I'm here too.
This bug makes Plasma Desktop Scripts completely useless for the user. We need to execute the scripts without user invervention.
Comment 16 Cristiano Guadagnino 2016-04-15 17:36:34 UTC
+1
Comment 17 Dmitry Nezhevenko 2016-06-03 13:39:18 UTC
+1
Comment 18 Egor 2016-12-11 17:10:30 UTC
A bit offtopic (for plasma4), but plasma 5.8 exposes the new function for direct script running:

  qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript $script

where $script is the actual script text (not the filename).

So if you (like me) found this bug when trying to deal with plasma 5, just upgrade your plasma.
Comment 19 Nate Graham 2018-06-08 20:03:10 UTC
Hello!

This feature request was filed for KDE Plasma 4, which reached end-of-support status in August 2015. KDE Plasma 5's desktop shell has been almost completely rewritten for better performance and usability, so it is likely that this feature request is already implemented in Plasma 5, or is no longer applicable.

Accordingly, we hope you understand why we must close this feature request. If the requested feature is still desired but not implemented in KDE Plasma 5.12 or later, please feel free to open a new ticket in the "plasmashell" product after reading https://community.kde.org/Get_Involved/Bug_Reporting

If you would like to get involved in KDE's bug triaging effort so that future mass bug closes like this are less likely, please read https://community.kde.org/Get_Involved#Bug_Triaging

Thanks for your understanding!

Nate Graham