This same problem is better formulated in a question posted to the Unix & Linux StackExchange community.
I am programming a script which opens on a key press, open a new terminal (gnome-terminal), runs scrot (screenshot tool), saves the picture with random name to a directory, uploads it to pomf.cat and copies the link to the clipboard.
This works fine. What im trying to do now is, when uploading is done, close the terminal.
My script works like this:
Shortcut (PrtScr) -> gnome-terminal -e "python path/to/script.py" -> Start Scrot -> Save File (and remember path to file) -> bash script2.sh path/to/picture -> Upload to pomf.cat -> Get the link -> Put into clipboard via "xclip -selection clipboard"
Since i want to close the Terminal after putting the String into Clipboard, i added this:
eval $(printf $link | xclip -selection clipboard && sleep 1 && pkill terminal)
The problem with this is, nothing gets copied into clipboard and the terminal closes.
However, without "&& sleep 1 && pkill terminal" the link gets copied but the terminal stays open.
Thanks in advance.
//EDIT
First Script (for running scrot)
#!/usr/bin/env python
import os
import uuid
import time
def rstring(string_length=10):
random = str(uuid.uuid4())
random = random.upper()
random = random.replace("-","")
return random[0:string_length]
randomString = rstring(16)
os.system("scrot -s -q 100 /home/timon/screenshots/" + randomString + ".jpg")
while True:
processRead = os.popen("ps aux | grep \"scrot -s\" | cat").read()
if "scrot -s" not in processRead:
time.sleep(1)
else:
break
system.sleep(3)
os.system("/home/timon/.screenshot_stuff/./screen.sh /home/timon/screenshots/" + randomString + ".jpg")
Second Script (for uploading the screenshot)
#!/usr/bin/env bash
dest_url='https://cuntflaps.me/upload.php'
return_url='https://a.cuntflaps.me'
if [[ -n "${1}" ]]; then
file="${1}"
if [ -f "${file}" ]; then
printf "Uploading ${file}..."
my_output=$(curl --silent -sf -F files[]="@${file}" "${dest_url}")
n=0 # Multipe tries
while [[ $n -le 3 ]]; do
printf "try #${n}...\n"
if [[ true ]]; then
return_file=$(echo "$my_output" | grep "url" | sed 's/\,//g' | sed 's/\\//g' | sed 's/\"//g' | sed 's/\url://g' | tr -d ' ')
printf 'done.\n'
break
else
printf 'failed.\n'
((n = n +1))
fi
done
printf "$return_file" | xclip -selection clipboard && pkill terminal
else
printf 'Error! File does not exist!\n'
exit 1
fi
else
printf 'Error! You must supply a filename to upload!\n'
exit 1
fi