Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How, floating pad for drag&drop URL to script?

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

How, floating pad for drag&drop URL to script?

#1 Post by bester69 »

Hi,
I would like to know how to get this done?.:

My idea is to launch a "small square/window floating pad" (no idea what tool to use here) with a shortcut-key, where I can drag&drop any file/url and once Its has been dropped over the pad area, It will automatic trigger a script with the dragged url as an argument for the bash script.

Any idea how to do this, any help?.. thanks
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

neuraleskimo
Posts: 195
Joined: 2019-03-12 23:26

Re: How, floating pad for drag&drop URL to script?

#2 Post by neuraleskimo »

Hi bester69,

I can think of a few ways to do what you want or at-least get you closer...

1) Back in the 1990's, many desktops would let you drop a file on the icon for a program. Doing so would launch the program and pass the file name as the first argument on the command line (recall that the zeroth argument is always the program name). Now days, programs on the desktop are no longer cool (e.g., Gnome is removing them), so this may no longer be possible.

2) If you use KDE, another option would be to create a Plasma widget that would live on your desktop. This would require a little more programming, but less than the next option.

3) You can write such an app in many languages. My favorite toolset, which may not be yours, is C++ and Qt. Qt has easy to use abstractions for GUI apps and drag-and-drop. Very briefly, you would create an instance of QMainWindow and then listen for drag-drop-events. Qt has great documentation and examples for all of this. If you prefer Python, Qt has bindings for Python. Alternatively, JavaScript and Electron are popular for GUIs.

4) I am assuming you want to build some kind of complex workflow where a user (maybe you) process files as they are collected or "arrive". In this case, you could take a serverless approach. The big three cloud providers will allow you to "hook" an event in their object stores (e.g., AWS S3) to code (e.g., AWS Lambda). In this way, when you drop a file into a directory specific code will be deployed and executed for each event. You can use a number of languages, but will need to use a cloud service.

5) If you like the serverless idea but do not want to use one of the big three cloud providers, you can implement the same idea on your workstation or server. Using Inotify, your application/daemon can monitor a directory and execute code on the arrival of a file. Again, you can use a number of programming languages.

Once you pick one (or maybe two) of the above approaches to explore, I can give you more specific advice. Also, if you have any questions about these options, don't struggle and please ask. I hope this helps...

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: How, floating pad for drag&drop URL to script?

#3 Post by bester69 »

neuraleskimo wrote:Hi bester69,
I can think of a few ways to do what you want or at-least get you closer...
.....

Once you pick one (or maybe two) of the above approaches to explore, I can give you more specific advice. Also, if you have any questions about these options, don't struggle and please ask. I hope this helps...
Hi neuraleskimo,
I wanted somethin easy to implement,for me.:

Opt2. seems might be ok, I dont know which would be te suitable wodget?
Opt3. seems the right way to go, but Im nor a programmer, and wouldnt like to investigate how to do it.. but i guess it must be easy.. perhaps I sould go this way.

Op5. Im considering this way as Its something Im able to implement.:
I would do it by using a floating noborder dolphin-folder (I use kde) window and Inotify, but dolphin ask confirmation before to drop anything, perhaps I'd have to use another file browser as dragging pad. For getting url name, I would have to use dragging copy file-link and process the url namefile.

Example; result of dragging urls links into dolphin folder.:
https:⁄⁄www.youtube.com⁄watch?v=BCKLONnWptE.desktop
http:⁄⁄forums.debian.net⁄posting.php?mode=quote&f=8&p=697536.desktop
then Iwould just need rise itotify script and to remove .desktop from filename

I think I would do this way..:o

Thanks a lot
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

Dai_trying
Posts: 1101
Joined: 2016-01-07 12:25
Has thanked: 5 times
Been thanked: 16 times

Re: How, floating pad for drag&drop URL to script?

#4 Post by Dai_trying »

I have created an empty gui and added drag and drop capability so you could use this and expand it to suit your needs, it has the ui file (you can easily edit this with qt designer) and a main python file where you can add your instructions for the dropped data. at the moment it simply prints the dropped data to the command line but you can do what you want with it.
When you run the python file it will open an empty GUI window and you can drag and drop stuff into it. I have only tested this with text ( the text from browser address bar) but it could be expanded to accept all sorts of media files too.
This is just a starting point really but I thought it might help you (if you choose the opt 3 route).

iface.ui

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>753</width>
    <height>113</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <widget class="QLabel" name="label">
      <property name="text">
       <string/>
      </property>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>753</width>
     <height>30</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>
main.py

Code: Select all

import sys
from PyQt4 import QtGui, uic

class MyWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()
        uic.loadUi('iface.ui', self)
        self.show()
        self.setAcceptDrops(True)

    def dragEnterEvent(self, e):
        print e

        if e.mimeData().hasText():
            e.accept()
        else:
            e.ignore()

    def dropEvent(self, e):
        print(e.mimeData().text())
        self.label.setText(e.mimeData().text())
    ####    Here you could add some functions or routines, or use
    ####    subprocess to run a bash script with the dropped data as a
    ####    parameter


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    window = MyWindow()
    sys.exit(app.exec_())
Just save them both as the proposed names and run

Code: Select all

python main.py
from the same location, obviously you would need pyqt4 installed for this particular example.

EDIT:
Added a label to the GUI to display text that is dropped
Last edited by Dai_trying on 2019-04-29 21:41, edited 1 time in total.

neuraleskimo
Posts: 195
Joined: 2019-03-12 23:26

Re: How, floating pad for drag&drop URL to script?

#5 Post by neuraleskimo »

Dai_trying wrote:I have created an empty gui and added drag and drop capability so you could use this and expand it to suit your needs, ...
Wow! +1 This looks like a pretty good framework for @bester69.
bester69 wrote:Op5. Im considering this way as Its something Im able to implement ...
If you want to continue along this path instead, there are a few ways to proceed...

1) Write a shell script. In this instance, you will want to install the "inotify-tools" package. Then, write a shell scrip that calls and blocks on "inotifywait" in a loop (probably easier than reading stdout which inotifywait will also allow) and performs what ever action you want.

2) Write a program in Python. In this instance, you will want to install the "inotify" package from pip ("pip install inotify"). See https://pypi.org/project/inotify/. Perhaps @Dai_trying can also give us some advice here.

Hope this helps...

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: How, floating pad for drag&drop URL to script?

#6 Post by bester69 »

hi,thanks for your help, I really appreciate it, will take a look to your solution when I can, it looks very promising..
you anticipate to me and Ive done my own one :|

I used for the floatting windows pad, a kde "rule windows" pointing to folder where inotifywait runs, and a XDG_CONFIG_HOME alternative for dolphin looks. This is the result, how it looks likes.. I drag url youtube to the pad, and it starts playing into QMPlay2.

Image

Image


runpad.sh

Code: Select all

/home/user/scripts/padfloating.sh &
XDG_CONFIG_HOME=$HOME/.altconfig dolphin 2> /dev/null &
padfloating.sh

Code: Select all

 #!/bin/sh
 #
 dir1=/home/user/LINUXDEBS/NOBACKUP/pad
 filedocs="/tmp/padfloat.txt"
killall inotifywait &
sleep 1
killall inotifywait -9
rm $dir1/*
cat /dev/null > "$filedocs"

 while inotifywait -qqre create --exclude .directory  "$dir1"; do
  find "$dir1/" -name "*.desktop" -exec echo "{}"  \; > "$filedocs"

  while read line; do
  PID=$(pgrep "QMPlay2")
if [ -z "$PID" ] 
then
QMPlay2 &
else
echo "nada"
fi
  sleep 1
 A=$(cat "$line"|grep URL)
 A="${A//URL[$}" && A="${A//e]=}"
 qplay  "$A" &
done < "$filedocs"
rm $dir1/* 
done
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

User avatar
pylkko
Posts: 1802
Joined: 2014-11-06 19:02

Re: How, floating pad for drag&drop URL to script?

#7 Post by pylkko »

One more solution could be to open a directory in a file manager where you can drag stuff.
Then use systemd.path to detect a new file and have it run a script on this.

a path to drag files into:
~/path/files

a filemonitor.service:

Code: Select all

[Unit]
Description=Automatically run script on file

[Service]
Type=oneshot
ExecStart=/bester/scripts/whatever.sh
a filemonitor.path:

Code: Select all

[Unit]
Description= monitor to start bester.service

[Path]
DirectoryNotEmpty=/home/bester/path/files


[Install]
WantedBy=multi-user.target
Then just write in your bash script to ls to fetch the name of the file/url (if the script also needs the actual name)


http://www.ocsmag.com/2015/09/02/monito ... r-dummies/

neuraleskimo
Posts: 195
Joined: 2019-03-12 23:26

Re: How, floating pad for drag&drop URL to script?

#8 Post by neuraleskimo »

pylkko wrote:One more solution could be to open a directory in a file manager where you can drag stuff.
Then use systemd.path to detect a new file and have it run a script on this.
Pretty cool. I did not know one could do that with systemd. Thanks for sharing.
bester69 wrote:I used for the floatting windows pad, a kde "rule windows" pointing to folder where inotifywait runs, and a XDG_CONFIG_HOME alternative for dolphin looks. This is the result, how it looks likes.. I drag url youtube to the pad, and it starts playing into QMPlay2. ...
I think what you have looks really good.

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: How, floating pad for drag&drop URL to script?

#9 Post by bester69 »

pylkko wrote:One more solution could be to open a directory in a file manager where you can drag stuff.
Then use systemd.path to detect a new file and have it run a script on this.
....
http://www.ocsmag.com/2015/09/02/monito ... r-dummies/
Thanks pylkko for tutorial, New interesting thing to learn, for dummies like me. :D , I like theses kind of stuff, so Im putting myself to reading it.

Thanks to all, guys.
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

User avatar
pylkko
Posts: 1802
Joined: 2014-11-06 19:02

Re: How, floating pad for drag&drop URL to script?

#10 Post by pylkko »

it's awesomely powerful and useful since in linux "everything is a file".

You can for example make scripts that run when devices are attached (automatic backup when USB storage attached) or when states of the kernel change, when a programs runs and much more. (think about files and content in /proc /sysfs /dev and so on).

Post Reply