Score:0

Drag'and'drop in a script

gb flag
msf

I want to use drag'n'drop in a script ,to work without mouse or keyboard intervention.This script should take (drag) some files and folders ,and put (drop) into the chroot environment inside the software Cubic.And after that to auto press the button "Copy" from Cubic.So all must be autonomous and automated. I searched all over here and on other sites/forums ,and found these discussions : https://unix.stackexchange.com/questions/216507/drag-and-drop-without-the-drag/557100#557100 https://unix.stackexchange.com/questions/137905/can-i-drag-a-file-into-a-window-without-a-file-manager

From first link I would like to use this scrip ,but I don't know how to modify it to work for what I want:

#!/usr/bin/env bash

doc="$0 <filename|'shot'>

With filename: Drags given file to where the mouse is using dragon.
               Click to drop it (anywere).
With 'shot'  : File will be a shot of a an area to be selected.
               => 'drag_into shot' on a hotkey combo makes sense. 
"

cmd_shot="shot"
file=

exit_help () { echo -e "$doc"; exit 1; }

select_shot_area () {
    # create screen shot
    notify-send "Select area - we'll shoot it and drag to where the mouse is."
    cd "$HOME/Pictures/shots/" || exit 1
    rm -f "latest.png"
    scrot -s '%Y-%m-%d_$wx$h_scrot.png' -e 'ln -s $f latest.png'
    file="`readlink latest.png`"
}

main () {
    file="$1"
    test -z "$file" -o "$file" == "-h" && exit_help
    eval "$(xdotool getmouselocation --shell)" # into $X and $Y
    test "$file" == "$cmd_shot" && { select_shot_area || return 1; }
    killall dragon 2>/dev/null # No accidential drops of wrong items ...
    dragon --and-exit "$file" &
    while true; do
        xid="$(xdotool search --onlyvisible --class  dragon | head -n 2)"
        test -z "$xid" || break
        sleep 0.05
    done
    xdotool mousemove --sync -w "$xid" 1 1 mousedown 1 mousemove $X $Y
    notify-send "Click to drop $file..."
}

main "$@"`

So could be modified this script ,or make/create a new and different one?And how?

24601 avatar
in flag
How does this relate to ubuntu? Generic programing questions should be asked on https://unix.stackexchange.com/questions
msf avatar
gb flag
msf
I use Ubuntu to do this.It's not related strictly to one of Ubuntu components ,but if you look here ,a lot of questions have nothing to do with Ubuntu components.
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.