Next

Bash GUI for QPDF (using Python)


 

Step 1: Create a python program called mergePDF.py

import PySimpleGUIQt as sg
import sys
import os 

arg = sys.argv[1:] 

current_working_directory = os.getcwd() + "/undefined.pdf"
current_working_directory = "/home/max/Scrivania" + "/undefined.pdf"


class Listbox(sg.Listbox):

    def dragEnterEvent(self, e):
        e.accept()

    def dragMoveEvent(self, e):
        e.accept()

    def dropEvent(self, e):
        data = window['LISTBOX'].get_list_values()
        items = [str(v).replace("PySide2.QtCore.QUrl('file://", "").replace("')", "") for v in e.mimeData().urls()]
        for x in items:
          if (x[-4:].upper() != '.PDF'): items.remove(x)        
        data.extend(items)
        window['LISTBOX'].update(data)
        window.refresh()

    def enable_drop(self):
        self.Widget.setAcceptDrops(True)
        self.Widget.dragEnterEvent = self.dragEnterEvent
        self.Widget.dragMoveEvent = self.dragMoveEvent
        self.Widget.dropEvent = self.dropEvent
        
file_list_column = [
     [ 
        Listbox(arg, size=(50, 10), enable_events=True, key='LISTBOX', select_mode="single"), 
     ],
     [
        sg.Input(default_text=current_working_directory, key='FOLDER')
     ],       
]

image_button_move_column = [  
   [sg.Button("Up")],
   [sg.Button("Down")],
   [sg.Button("Delete")],  
]
       

image_button_action_column = [
   [
      sg.Button("Merge")
   ],
]

layout = [
   [
        sg.Column(file_list_column),
        sg.VSeperator(),
        sg.Column(image_button_move_column),
        sg.VSeperator(),
        sg.Column(image_button_action_column),
   ]
]   

window = sg.Window("pdfMerge V1.0", layout, finalize=True, resizable=False)
window['LISTBOX'].enable_drop()

def retreive_elem_selected(element):
    if element['LISTBOX']: 
       item = element['LISTBOX'][0]
    else: item = ""    
    return item      


def manage_up(item, mylist):
    if item:
       pos = mylist.index(item)
       newpos = pos-1
       if newpos>-1:
          mylist.insert(
             newpos,
             mylist.pop(pos)
            )  
    return mylist
       
def manage_down(item, mylist):
    if item:
       pos = mylist.index(item)
       newpos = pos+1
       mylist.insert(
             newpos,
             mylist.pop(pos)
            )  
    return mylist       
       

def manage_delete(item, mylist):
    if item:
       mylist.remove(item)
    return mylist 
    
def manage_merge(mylist,myfile):
    if myfile:
       str1 = " ".join(str("\""+x+"\"") for x in mylist) 
       os.system("qpdf --empty --pages "+ str1 + " -- " + myfile)  
    else: sg.popup('','The output field is empty') 
    
while True:

    event, values = window.read()
    
    item_selected = retreive_elem_selected(values)
    mylist = window['LISTBOX'].get_list_values()
    
    if event == sg.WINDOW_CLOSED:
       break
        
    if event == 'Merge':
       manage_merge(mylist,window['FOLDER'].get())    
       
    if event == 'Up':
       window['LISTBOX'].update(manage_up(item_selected,mylist))
       window['LISTBOX'].set_value(item_selected)
             
    if event == 'Down':
       window['LISTBOX'].update(manage_down(item_selected,mylist))
       window['LISTBOX'].set_value(item_selected)
       
    if event == 'Delete': 
       if item_selected:
          pos = mylist.index(item_selected)
          window['LISTBOX'].update(manage_delete(item_selected,mylist))
          mylist = window['LISTBOX'].get_list_values()
          if mylist:
             if pos < len(mylist): 
                window['LISTBOX'].set_value(mylist[pos])
             else: window['LISTBOX'].set_value(mylist[-1:])                    

   
    
window.close()
  
Step 2:  create a bash file mergePDF.sh to run the mergePDF.py

#!/bin/bash
python3 /home/max/batfile/Py/mergePDF.py "$@"
  
where /home/max/batfile/Py/ is the path where your python file is stored

Step 3:  create a link of mergePDF.sh file into scripts folder
    in my case into /home/max/.local/share/nautilus/scripts
  

How to run powershell from TaskActivity of Window

 Use as Program or script: c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe

and as arg use -executionpolicy bypass -file "C:\Temp\example.ps1"

where example.ps1 contain your script

The Real Home Automation: Home Assistant

 https://www.home-assistant.io/


# Example script integration containing script syntax
script:
  example_script:
    sequence:
      # This is written using the Script Syntax
      - alias: "Turn on ceiling light"
        service: light.turn_on
        target:
          entity_id: light.ceiling
      - alias: "Notify that ceiling light is turned on"
        service: notify.notify
        data:
          message: "Turned on the ceiling light!"

How to extract mp3 from youtube





  • Install yt-dlp_linux

from https://github.com/yt-dlp/yt-dlp go su release and download linux yt-dlp_linux,
put all into a new folder ad assign the execution permission.


  • Download a specific video, i.e:

./yt-dlp_linux -x --audio-format mp3 https://www.youtube.com/watch?v=cen1SvpTsYk&ab_channel=BlackSabbath






Convert mp4 to mp3 under linux

 
#!/bin/bash
clear

# Example: ./mp4ToMp3.sh ~/Downloads

for entry in "$1"/*.mp4
do
  
  ext="${entry##*.}"
  filename="${entry:0:${#entry} - ${#ext}}"
  mp3file="${filename}mp3" 
  echo "$entry ===> $mp3file"
  ffmpeg -i "$entry" -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 "$mp3file"
done

GUI for SECurity

Create a file called security.sh under ~/myscript directory
 
#!/bin/bash

unsecAction()
{
  retValue=$(zenity --password   --title="SECurity")
  
  case $? in
      0)
		 	password=$(echo $retValue | cut -d'|' -f1) 
		 	~/bin/security $fileSec $password
			;;
	  1)
            endmenu
            ;;
     -1)
		    endmenu
		   ;;
  esac  
	  
   
}

secAction()
{
  retValue=$(zenity --forms --title="SECurity" --text="Add a security password" --add-password="Password" --add-password="Re-password" )
  
  case $? in
      0)
		 	password1=$(echo $retValue | cut -d'|' -f1)
		 	password2=$(echo $retValue | cut -d'|' -f2) 
		 	
		 	if [ $password1 == $password2 ]
            then         
              ~/bin/security $fileSec $password1           
            else
              zenity --info --text="Different Passwords" 
              secAction       
            fi		 	
			;;
	  1)
            endmenu
            ;;
     -1)
		    endmenu
		   ;;
  esac  
	  
   
}

endmenu() {
  echo "Bye bye."
  exit 0;
}


mainmenu() 
{
 declare -i count
 count=0
 
 IFS=$(echo -en "\n\b")
 read -ra files <<< "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" 
   
 for file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
 do
     let count++
 done
 
 
 
 if [ $count -gt 1 ]
 then
   zenity --info --text="Select only one file"
 else
 
   if [ -f $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ]
   then
       ext="${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS##*.}"
       fileSec=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
       
       if [ $ext == "sec" ]
       then         
         unsecAction           
       else
        secAction        
       fi
	      
   else
	   zenity --info --text="Select a file. It's a directory"   
   fi 
 fi
}

mainmenu

create a link of security.sh file called SECurity
and move it under ~/.local/share/nautilus/scripts

run the command 

chmod +x ~/myscript/security.sh
chmod +x ~/.local/share/nautilus/scripts/SECurity

Now when you open the context menu you will see:




Now download this file (security) from  here   
and put under ~/bin directory

then run the command:

chmod +x ~/bin/security

Bash GUI for QPDF

 
#!/bin/bash

endmenu() {
  echo "Bye bye."
  exit 0;
}

getDestinationFile() 
{
   retValue=$(zenity --file-selection  --save --file-filter='PDF files (pdf) | *.pdf' --title="Select a PDF file (Destination)")
 
	case $? in
		0)
		    destinationPDFFile=$retValue
		    ;;
	esac
}

getOriginFiles() 
{
   retValue=$(zenity --file-selection  --multiple --file-filter='PDF files (pdf) | *.pdf' --title="Select a PDF files to merge")
 
	case $? in
		0)
		    originPDFFiles=$retValue
		    ;;
	esac
}

showOriginFiles()
{
   declare -i index
   index=1
   mylistFiles=()
   tmpmylistFiles=()
   IFS='|' 
   
   read -ra files <<< "$originPDFFiles"  
   for file in "${files[@]}";
   do
 	 tmpmylistFiles+=("$file" ) 
   done
   
   readarray -t tmpmylistFiles < <(printf '%s\n' "${tmpmylistFiles[@]}" | sort)
      
   for file in "${tmpmylistFiles[@]}";
   do
 	 mylistFiles+=("$index" "$file" )
	 let index++
   done    
   
   retValue=$(zenity --list  --hide-header --height=400 --width=700  --title='Files To Merge' --column=ID --column=Files  "${mylistFiles[@]}" ) 
   echo $retValue
 
}

mergeFiles()
{
   mylistFiles=()
   IFS='|'
   continua=1
   
   if [ -z "${destinationPDFFile}" ]; then   
     zenity --info --text="No destination file selected."
     continua=0
   fi
   
   if [ $continua == 1 ]; then 
	   if [ -z "${originPDFFiles}" ]; then   
		 zenity --info --text="No select files to merge."
		 continua=0
	   fi   
   fi
   
   if [ $continua == 1 ]; then
   
	   read -ra files <<< "$originPDFFiles"  
	   for file in "${files[@]}";
	   do
	   echo $file
		 mylistFiles+=("$file" ) 
		 let index++
	   done  
	   
	   readarray -t mylistFiles < <(printf '%s\n' "${mylistFiles[@]}" | sort)
	   
	   qpdf --empty --pages "${mylistFiles[@]}" -- "${destinationPDFFile}"
   fi   
}

mainmenu() 
{
	choice=$(zenity --height=250 --list  --hide-header --text "Select action" --ok-label="Select" --cancel-label="Exit" \
	                --title "Main Menu - Merge file" --radiolist  --column="ID" --column="Action" \
	                1 "File Destination" 2 "Add Files To Merge" 3 "View Files To Merge" 4 "Merge" )

	case $choice in
		     "File Destination")
								getDestinationFile
								mainmenu
		            			;;
		     "Add Files To Merge") 
								getOriginFiles
								mainmenu
		            			;;
		     "View Files To Merge")
							   showOriginFiles                   		     
							   mainmenu
		           			   ;; 
		     "Merge")
		                       mergeFiles
		                       mainmenu
		           	           ;;
	esac

}




mainmenu

Error 0x00000011b network printer (0x00000709)


 


To resolve in this way:

In the computer where the printer is connected

1) open regedit as administrator

2) create under 

KEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ Print \


the value  

RpcAuthnLevelPrivacyEnabled ( as REG_DWORD (32) and set it to zero )

3) Re-start the computer.



For Error: 0x00000709


3. Change RPC Connection Settings

Once you've changed the printer name, you should ensure your printer is connected to the network. If it's connected, but you're still getting the error, modify the RPC connection settings in the group policy editor. This policy controls the protocol settings for outgoing RPC connections to a remote print spooler.

To enable and change the policy settings, follow these steps:

  1. Type "Group Policy" in Windows Search. See how to find and use Windows Search if you need help with this.
  2. Click on Edit group policy.
  3. In the left-sidebar, select Administrative Templates > Printers.
    Clicking on the Printers Option in the Administrative Templates Dropdown in Windows Group Policy Editor App
  4. Click Configure RPC connection settings twice.
  5. To enable this policy, check the circle for Enabled.
  6. Select RPC over named pipes from the dropdown menu for Protocol to use for outgoing RPC connections.
    Selecting RPC Over Named Pipes from the Dropdown Menu of Protocol to Use for Outgoing RPC Connections in Windows Group Policy Editor App
  7. Hit OK after clicking Apply.
  8. Restart your device.