Forum › Forums › General › Software › Appimage2menu – script to integrate appimages in the antiX menu
- This topic has 2 replies, 2 voices, and was last updated Dec 16-4:21 pm by oops.
-
AuthorPosts
-
December 16, 2022 at 12:17 am #95734Member
PPC
After several attempts, I think I’m getting close to a finished script to integrate appimages into the antiX menu.
Anyone interested, please test the script- it creates, the relevant .desktop file in /usr/share/applications/, with the prefix “appimage_”, so you can easily delete them if necessary. (lets hope the forum does not mangle the code)
Dependency: 7z (to extract the files from inside the appimage)
Usage:
[script_name] [path_to_appimage_to_integreate_in_the_menu]
if asked to, enter your root password (it’s needed to copy the .destop file to /usr/share/applications/ )#!/bin/bash #script to generate a valid .desktop file to launch an appimage # dependencies: 7z #use appimage for the terminal: #Clean temp folder: rm -rf /tmp/appimage/* #Check if an appimage file was provided: var="$@" if [ -n "$var" ]; then echo "This script is being run on a appimage file..." else echo "There was no appimage file to add to the menu" exit fi #Start main script: for FILE1 in "$@" do ###make sure that the appimage is executable chmod a+x $FILE1 ###### extract .desktop from appimage: 7z e $FILE1 usr/share/applications/ -y echo $FILE1 > /tmp/appimage_path -y ### extract png icon from appimage: #list appimage's contents 7z l $FILE1 > /tmp/list.txt -y #find lines that contain only ".png" and "usr/share": grep -n ".desktop" /tmp/list.txt > /tmp/lines_with_desktop.txt grep -n ".png" /tmp/list.txt > /tmp/lines_with_png.txt grep -n "usr/share" /tmp/lines_with_png.txt >/tmp/lines_with_png_and_usr_share.txt var=$(cat /tmp/lines_with_png_and_usr_share.txt) #strip everything up to "usr": var=$(echo "${var#*usr}") echo $var icon_path=$(echo usr$icon) #.desktop file(s) location inside appimage: echo .desktop files inside appimage: desk_file=$(cat /tmp/lines_with_desktop.txt| awk '{print $NF}') echo $desk_file #extract the .desktop file: eval 7z e $FILE1 $desk_file -o/tmp/appimage echo $FILE1 > /tmp/appimage_file_path.txt done #Make sure that only the real appimage remains (the bigger one) cd /tmp/appimage file=$(du -ah *.desktop | sort -hr | head -n 1| awk '{print $2;}') echo $file is a real .desktop file cat /tmp/appimage/$file echo The file name will be appimage_$file sleep 2 echo appimage_$file > /tmp/appimage/name cat /tmp/appimage/$file > /tmp/appimage/real.desktop # Now the real usefull work: substitute, the Exec command inside the .desktop file! # get the first line that contains "Exec=" (because there can be several EXEC's) original_exec1=$(grep "^Exec=" /tmp/appimage/real.desktop | head -n1) original_exec=$(echo $original_exec1 | awk '{print $1;}') new_exec1=$(cat /tmp/appimage_file_path.txt) new_exec=$(echo Exec=$new_exec1) echo old exec is $original_exec echo new exec is: $new_exec #Alter path of the extracted .desktop file to launch the appimage itself: appimage_location=$(cat /tmp/appimage_path) original="Exec=$original_exec" sed -i "s:$original_exec:$new_exec :" /tmp/appimage/real.desktop name=$(cat /tmp/appimage/name) cp /tmp/appimage/real.desktop /tmp/appimage/$name #Get appimage's icon: icon=$(cat /tmp/appimage/$name| grep "Icon="| cut -d'=' -f2) ###| cut -d'.' -f1) icon1="$icon.png" icon2="$icon.svg" cd $HOME touch ./appimage_icons cd $HOME/appimage_icons 7z e $FILE1 $icon1 7z e $FILE1 $icon2 #replace icon on the generated .desktop file with the extracted one -- add -i !!!! sed -i "s:Icon=.*:Icon=$HOME/appimage_icons/$icon :" /tmp/appimage/$name #copy the generated .desktop file to the /usr/share/applications folder ########To do: check sudo then, if needed, use gksu, instead of sudo sudo cp /tmp/appimage/$name /usr/share/applications/$name #clean up: rm -rf /tmp/appimage/* ###Update antiX menu sudo desktop-menu --write-out-global ###TO DO: Yad window asking user to test the new desktop, if it does not work, delete it... ###end of scriptEdit: I tested this script even further and it has yet to fail to work – it always adds the correct .desktop file to the menu… But getting the correct icon for it is still a bit hit or miss- I notice it usually works fine with .svg icons, not really that well with .png one… I’ll try to take a look a it today…
- This topic was modified 4 months, 3 weeks ago by PPC.
- This topic was modified 4 months, 3 weeks ago by PPC.
- This topic was modified 4 months, 3 weeks ago by PPC.
December 16, 2022 at 11:31 am #95756Member
oops
::… Nice and useful script PPC … What works great here (even under MX linux)
[script_name] [path_to_appimage_to_integreate_in_the_menu]
from: /MyDir/otter-browser-0.9.99.3-rc12-x86_64.AppImage
to: /usr/share/applications/appimage_otter-browser.desktop… But for me, it is better to keep the same name as the original Appimage: so : “appimage_otter-browser-0.9.99.3-rc12-x86_64.desktop”
[Desktop Entry] # Name=Otter Browser Name=appimage_otter-browser-0.9.99.3-rc12-x86_64 ...Edit: and maybe an option can be added for a firejail launcher ?, like :
firejail –appimage MyAppimage –> /usr/share/applications/appimage_firejail__otter-browser-0.9.99.3-rc12-x86_64.desktop- This reply was modified 4 months, 3 weeks ago by oops.
- This reply was modified 4 months, 3 weeks ago by oops.
- This reply was modified 4 months, 3 weeks ago by oops.
December 16, 2022 at 4:21 pm #95771Member
oops
::For info,
An Appimage can already do that:https://gitlab.com/posktomten/appimagehelper/-/wikis/Help
https://gitlab.com/posktomten/appimagehelper/-/wikis/DOWNLOADS
-
AuthorPosts
- You must be logged in to reply to this topic.