Forum › Forums › General › Tips and Tricks › Shortcut Maker – easy, none keyboard needed auto fill and auto generate shortcut
- This topic has 9 replies, 3 voices, and was last updated Mar 9-12:17 pm by Lead Farmer.
-
AuthorPosts
-
March 5, 2023 at 2:03 pm #101198Member
Lead Farmer
This script will a generate a shortcut in the …/.local/share/applications folder or the Desktop folder, it will automatically fill all the needed the values as Name, Exec, Icon, Type, Categories and Comment, and the save a file in the folder.
I will cause an icon and name to show in the menu or in the desktop, and is will make the file executable.This scrip meant to work from the file manger, but can also work from the terminal. I will show how to make it work from the Nemo file manger, but if you know how to make it work in other file mangers like zzzFM please post it here.
The script
#!/bin/bash # # Shortcut Maker - easy, none keyboard needed, auto pill and auto genrated shortcut # NAME=$(echo "$1" | grep -Po '(?<=\/)[^\/\.]*($|(?=\.))') APPS="/home/$(whoami)/.local/share/applications/" DESKTOP="/home/$(whoami)/Desktop/" if test -f "$1"; then chmod +x "$1" FOLDER=$(yad --width=400 --center --borders=20 --button=gtk-ok:0 --buttons-layout=center --title="Select Location" --form --date-format="%-d %B %Y" --item-separator="," --field="Location":CB "$APPS,$DESKTOP" | awk -F "|" '{print $1}') rm "$FOLDER$NAME.desktop" else yad --width=200 --center --buttons-layout=center --borders=5 --text-align=center --title="Error" --text="File don't exist!" --button=gtk-ok:1 --center exit 0 fi yad --width=600 --center --borders=20 --title="Shortcut Maker" --text="Please enter the shortcut details:" \ --form --date-format="%-d %B %Y" --item-separator="," \ --field="Name" \ --field="Exec file" \ --field="Icon":FL \ --field="Category":CBE \ --field="Comment" \ --field="Location":CB \ "$NAME" "$1" "/usr/share/antiX/icons/logo_antiX.png" "Accessories,Games,Graphics,Internet,Multimedia,Office,Preferences,Programming,System" "Start $NAME" "$FOLDER" \ | awk -F "|" '{print "[Desktop Entry]\nName="$1"\nExec=\""$2"\"\nIcon="$3"\nType=Application""\nCategories="$4";\nComment="$5 >> $6$1".desktop"}' sleep 1 desktop-menu --write-out-global exit 0Running the script from the terminal example:
bash /path/script.sh "/home/something/something/file"Running the script from Nemo file manger
I the folder /home/oren/.local/share/nemo/actions create a file name “descktop.nemo_action” and copy this:
[Nemo Action] Name=Create shortcut Comment=Create shortcut in Applications or Desktop Exec= bash /path/script.sh "%F" Icon-Name=yad Selection=Any Extensions=any;And restart nemo.
Note:
1) The default icon is an antix icon, if one is not selected.
2) When running the script is will check if there is name.desktop file in the folder, and if so it will be deleted before generating a new one.- This topic was modified 2 months ago by Lead Farmer.
- This topic was modified 2 months ago by Lead Farmer.
March 5, 2023 at 3:01 pm #101208MemberRJP
March 5, 2023 at 3:11 pm #101211MemberLead Farmer
::I get “File don´t exist error.
So the path of the file is note correct, you need to give a full path.
bash /path/script.sh "/home/something/something/file"March 7, 2023 at 9:20 am #101334MemberRJP
::Your script is too complicated. It works after removing some lines.
#!/bin/bash # # Shortcut Maker - easy, none keyboard needed, auto pill and auto genrated shortcut # APPS="/home/$(whoami)/.local/share/applications/" DESKTOP="/home/$(whoami)/Työpöytä/" FOLDER=$(yad --width=400 --center --borders=20 --button=gtk-ok:0 --buttons-layout=center --title="Select Location" --form --date-format="%-d %B %Y" --item-separator="," --field="Location":CB "$APPS,$DESKTOP" | awk -F "|" '{print $1}') rm "$FOLDER$NAME.desktop" yad --width=600 --center --borders=20 --title="Shortcut Maker" --text="Please enter the shortcut details:" \ --form --date-format="%-d %B %Y" --item-separator="," \ --field="Name" \ --field="Exec file" \ --field="Icon":FL \ --field="Category":CBE \ --field="Comment" \ --field="Location":CB \ "$NAME" "$1" "/usr/share/antiX/icons/logo_antiX.png" "Accessories,Games,Graphics,Internet,Multimedia,Office,Preferences,Programming,System" "Start $NAME" "$FOLDER" \ | awk -F "|" '{print "[Desktop Entry]\nName="$1"\nExec=\""$2"\"\nIcon="$3"\nType=Application""\nCategories="$4";\nComment="$5 >> $6$1".desktop"}' sleep 1 desktop-menu --write-out-global exit 0##################################
Edit:
When I tested, I commented out lines and I made a typo when I wrote here. Now typo is corrected.##################################
Edit 2:
It works without line NAME=$(echo “$1” | grep -Po ‘(?<=\/)\w+’ | tail -1) also.- This reply was modified 2 months ago by RJP.
- This reply was modified 2 months ago by RJP.
Attachments:
March 7, 2023 at 10:10 am #101336MemberLead Farmer
::Your script is too complicated. It works after removing some lines.
The “if” section is to check if the file is exist before it continue.
The script you post missing some values, here the correction:
#!/bin/bash # # Shortcut Maker - easy, none keyboard needed, auto pill and auto genrated shortcut # NAME=$(echo "$1" | grep -Po '(?<=\/)\w+' | tail -1) APPS="/home/$(whoami)/.local/share/applications/" DESKTOP="/home/$(whoami)/Desktop/" FOLDER=$(yad --width=400 --center --borders=20 --button=gtk-ok:0 --buttons-layout=center --title="Seclect Location" --form --date-format="%-d %B %Y" --item-separator="," --field="Location":CB "$APPS,$DESKTOP" | awk -F "|" '{print $1}') rm "$FOLDER$NAME.desktop" yad --width=600 --center --borders=20 --title="Shortcut Maker" --text="Please enter the shortcut details:" \ --form --date-format="%-d %B %Y" --item-separator="," \ --field="Name" \ --field="Exec file" \ --field="Icon":FL \ --field="Category":CBE \ --field="Comment" \ --field="Location":CB \ "$NAME" "$1" "/usr/share/antiX/icons/logo_antiX.png" "Accessories,Games,Graphics,Internet,Multimedia,Office,Preferences,Programming,System" "Start $NAME" "$FOLDER" \ | awk -F "|" '{print "[Desktop Entry]\nName="$1"\nExec=\""$2"\"\nIcon="$3"\nType=Application""\nCategories="$4";\nComment="$5 >> $6$1".desktop"}' sleep 1 desktop-menu --write-out-global exit 0Also I changed the NAME, so it will only show the name up to none letters or numbers.
- This reply was modified 2 months ago by Lead Farmer.
March 7, 2023 at 3:06 pm #101353MemberRJP
::You are correct. Line NAME=$(echo “$1” | grep -Po ‘(?<=\/)\w+’ | tail -1) must has been in buffer when I tested the script. 🙂
PS. If you use different locale, Desktop name must be changed
To check desktop locale
cat $HOME/.config/user-dirs.dirs | grep DESKTOPMine is
XDG_DESKTOP_DIR="$HOME/Työpöytä"- This reply was modified 2 months ago by RJP.
March 7, 2023 at 3:16 pm #101357MemberLead Farmer
::You are correct. Line NAME=$(echo “$1” | grep -Po ‘(?<=\/)\w+’ | tail -1) must has been in buffer when I tested the script.
You also need the FOLDER tho decide where to add the file in in desktop or applictions.
If you what you can skip that part by replacing removing $FOLDER script, and replacing it with $DESKTOP or $APPS.
- This reply was modified 2 months ago by Lead Farmer.
March 7, 2023 at 3:43 pm #101360MemberPPC
::I’ve not tested the script until now.
first thing: does putting a .desktop file in ~/.local/share/applications/ and then running desktop-menu –write-out-global with elevated privileges make the corresponding entry to that .desktop file appear in your menu? It does not in IceWM (the script that generates the menu does not look for .desktop files in that folder). Of course the entry appears in app-select, or in a rofi launcher, or in jgmenu (that is the menu used in FT10). Have you edited somthing to make the default menu generator script look in that folder?
Second: as always, nice idea. antiX as (or had) a similar script. My suggestion? Why not make the initial window one with 2 buttons: “Create Menu entry” “Create Desktop icon”. It’s faster than selecting the option from a drop down box and clicking the “ok” button…
Third: a GUI for creating an icon on the desktop, for application that has a .desktop entry, will be soon available for IceWM, but this script does allow to create icons for just about any application.
DESKTOP=”/home/$(whoami)/Desktop/” won’t work for systems that are not in english – you can use “$XDG_DESKTOP_DIR” instead, so the script works for everyone.
Also, using “/home/$(whoami)” is too complex- why not simply “$HOME”?Like I said, very nice idea!
P.
March 7, 2023 at 4:19 pm #101366MemberLead Farmer
::first thing: does putting a .desktop file in ~/.local/share/applications/ and then running desktop-menu –write-out-global with elevated privileges make the corresponding entry to that .desktop file appear in your menu? It does not in IceWM (the script that generates the menu does not look for .desktop files in that folder). Of course the entry appears in app-select, or in a rofi launcher, or in jgmenu (that is the menu used in FT10). Have you edited somthing to make the default menu generator script look in that folder?
It does, I also use IceWM, you can see in the images that I post it shows in the menu and the Application Finder.
Second: as always, nice idea. antiX as (or had) a similar script. My suggestion? Why not make the initial window one with 2 buttons: “Create Menu entry” “Create Desktop icon”. It’s faster than selecting the option from a drop down box and clicking the “ok” button…
It can be done, it’s just more steps in the end I need to add the address desktop or applications to the yad.
Third: a GUI for creating an icon on the desktop, for application that has a .desktop entry, will be soon available for IceWM, but this script does allow to create icons for just about any application.
Good to know, although I don’t use icon in the desktop.
DESKTOP=”/home/$(whoami)/Desktop/” won’t work for systems that are not in english – you can use “$XDG_DESKTOP_DIR” instead, so the script works for everyone.
Also, using “/home/$(whoami)” is too complex- why not simply “$HOME”?I didn’t know that. Good idea
- This reply was modified 2 months ago by Lead Farmer.
- This reply was modified 2 months ago by Lead Farmer.
March 9, 2023 at 12:17 pm #101548MemberLead Farmer
::Shortcut Maker
2.02.1I decided to implement @PPC suggestions,fix some bugs and add an version that it more easy to run without a terminal.
1) Replace $(whoami) with “$HOME” so it will work with none English languages.
2) Replace in “Select Location” window the address with buttons “Create Menu entry” and “Create Desktop icon”.
3) Bug fix: some of the names in Menu > Applications are not corresponding with names in the file .desktop unther the “Categories=” section, and need to replaced.
Here is the names in the Menu corresponding to categories names:
Accessories -> Accessories
Games -> Game
Graphics -> Graphics
Internet -> Network
Multimedia -> AudioVideo
Office -> Office
Preferences -> Settings
Programming -> Development
System -> SystemVersions: In the zip there are two file:
1) shortcut_maker.sh: in this version you just need to enter the path of the file (see images)
2) shortcut_maker_nemo.sh: This version work with Nemo File Manger or the Terminal see post #1
Please test this version and tell me if it work ok.
Edit:post 2.1 version
- This reply was modified 2 months ago by Lead Farmer.
- This reply was modified 2 months ago by Lead Farmer.
- This reply was modified 2 months ago by Lead Farmer.
-
AuthorPosts
- You must be logged in to reply to this topic.








