Linuxでソフトウェアのショートカットアイコンを作成する方法

まず、私の環境を説明しますと、私は遊ぶのが好きなので、ubuntu22.04、openuse 15.5、manjora という 3 つのオペレーティング システムをコンピューターにインストールし、通常はこれらを入れ替えて使用しています。これら 3 つのシステムはそれぞれ別のルート パーティション / および /root パーティションを使用しますが、同じデータ パーティション /u01 をマウントします (データ ファイルやソフトウェアなどを保存します)。

これら 3 つのオペレーティング システムには、libreoffice、typora など、私が通常使用するソフトウェアがすべてインストールされています。

以前は、deb バージョンのソフトウェアを ubuntu に、rpm バージョンのソフトウェアを opensuse に、バイナリ バージョンのソフトウェアを manjaro にインストールする必要がありました。

その後、多くの Linux ソフトウェアには appimage バージョンがあり、インストールせずに実行できることがわかりました。たとえば、navicat や、idea などの一部のソフトウェアは、解凍さえすれば実行できます。

そこで、rpm/deb バージョンを放棄し、代わりに appimage とバイナリ圧縮パッケージをダウンロードすることにしました。そのため、.desktop ファイルが形式に従って /usr/share/applications に作成されている限り、対応するアイコンがスタートメニューを開くだけで実行できるのでとても便利です。

この方法では、3 つのシステムに個別に deb/rpm/binary パッケージをインストールする必要はありません。スクリプトを作成し、オペレーティング システムをインストールし、スクリプトを実行し、ソフトウェアの .desktop を作成するだけです。

ほとんどの .desktop ファイルは似ていますが、主な項目は 2 つだけです。1 つはプログラムのパス、もう 1 つはプログラムのアイコンです。rpm/deb インストールと同じ効果を得るために、rpm/deb インストールによって生成された .desktop ファイルの内容を参照し、appimage から元のアイコンを抽出します。参照用に、作成スクリプトを以下に書き留めます。

libreoffice、appimage ソフトウェア、バイナリ圧縮パッケージ ソフトウェアの 3 つの部分に分かれています。

libreoffice ソフトウェアには、writer、calc、math、impress、base、draw などが含まれており、それぞれ word、excel、powerpoint、access、viso、その他のオフィス ソフトウェアに対応します。対応するオフィス製品が無いmath(数式エディタ)もあり、libreofficeが入り口に相当します。したがって、作成するショートカットは合計 7 つになります。

書き方は少し複雑なので別途記載します。ubuntu22.04/opensuse 15.5/manjaro の両方がテストに合格しました

#libreoffice
cat > /usr/share/applications/libreoffice-startcenter.desktop <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
NoDisplay=false
Icon=libreoffice-startcenter
Type=Application
Categories=Office;X-Red-Hat-Base;X-SuSE-Core-Office;X-MandrivaLinux-Office-Other;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage %U
MimeType=application/vnd.openofficeorg.extension;x-scheme-handler/vnd.libreoffice.cmis;x-scheme-handler/vnd.sun.star.webdav;x-scheme-handler/vnd.sun.star.webdavs;x-scheme-handler/vnd.libreoffice.command;x-scheme-handler/ms-word;x-scheme-handler/ms-powerpoint;x-scheme-handler/ms-excel;x-scheme-handler/ms-visio;x-scheme-handler/ms-access;
Name=LibreOffice
GenericName=Office
Comment=The office productivity suite compatible to the open and standardized ODF document format. Supported by The Document Foundation.
StartupNotify=true
X-GIO-NoFuse=true
StartupWMClass=libreoffice-startcenter
X-KDE-Protocols=file,http,ftp,webdav,webdavs
X-AppStream-Ignore=True

Actions=Writer;Calc;Impress;Draw;Base;Math;

[Desktop Action Writer]
Name=Writer
Exec=libreoffice --writer

[Desktop Action Calc]
Name=Calc
Exec=libreoffice --calc

[Desktop Action Impress]
Name=Impress
Exec=libreoffice --impress

[Desktop Action Draw]
Name=Draw
Exec=libreoffice --draw

[Desktop Action Base]
Name=Base
Exec=libreoffice --base

[Desktop Action Math]
Name=Math
Exec=libreoffice --math
EOF

cat > /usr/share/applications/libreoffice-writer.desktop  <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
Icon=libreoffice-writer
Type=Application
Categories=Office;WordProcessor;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --writer %U
MimeType=application/vnd.oasis.opendocument.text;application/vnd.oasis.opendocument.text-template;application/vnd.oasis.opendocument.text-web;application/vnd.oasis.opendocument.text-master;application/vnd.oasis.opendocument.text-master-template;application/vnd.sun.xml.writer;application/vnd.sun.xml.writer.template;application/vnd.sun.xml.writer.global;application/msword;application/vnd.ms-word;application/x-doc;application/x-hwp;application/rtf;text/rtf;application/vnd.wordperfect;application/wordperfect;application/vnd.lotus-wordpro;application/vnd.openxmlformats-officedocument.wordprocessingml.document;application/vnd.ms-word.document.macroEnabled.12;application/vnd.openxmlformats-officedocument.wordprocessingml.template;application/vnd.ms-word.template.macroEnabled.12;application/vnd.ms-works;application/vnd.stardivision.writer-global;application/x-extension-txt;application/x-t602;text/plain;application/vnd.oasis.opendocument.text-flat-xml;application/x-fictionbook+xml;application/macwriteii;application/x-aportisdoc;application/prs.plucker;application/vnd.palm;application/clarisworks;application/x-sony-bbeb;application/x-abiword;application/x-iwork-pages-sffpages;application/x-mswrite;application/x-starwriter;
Name=LibreOffice Writer
GenericName=Word Processor
Comment=Create and edit text and graphics in letters, reports, documents and Web pages by using Writer.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Text;Letter;Fax;Document;OpenDocument Text;Microsoft Word;Microsoft Works;Lotus WordPro;OpenOffice Writer;CV;odt;doc;docx;rtf;
InitialPreference=5
StartupWMClass=libreoffice-writer
X-KDE-Protocols=file,http,ftp,webdav,webdavs

Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Document
Icon=document-new
Exec=libreoffice --writer
EOF

cat > /usr/share/applications/libreoffice-calc.desktop  <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
Icon=libreoffice-calc
Type=Application
Categories=Office;Spreadsheet;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --calc %U
MimeType=application/vnd.oasis.opendocument.spreadsheet;application/vnd.oasis.opendocument.spreadsheet-template;application/vnd.sun.xml.calc;application/vnd.sun.xml.calc.template;application/msexcel;application/vnd.ms-excel;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.ms-excel.sheet.macroEnabled.12;application/vnd.openxmlformats-officedocument.spreadsheetml.template;application/vnd.ms-excel.template.macroEnabled.12;application/vnd.ms-excel.sheet.binary.macroEnabled.12;text/csv;application/x-dbf;text/spreadsheet;application/csv;application/excel;application/tab-separated-values;application/vnd.lotus-1-2-3;application/vnd.oasis.opendocument.chart;application/vnd.oasis.opendocument.chart-template;application/x-dbase;application/x-dos_ms_excel;application/x-excel;application/x-msexcel;application/x-ms-excel;application/x-quattropro;application/x-123;text/comma-separated-values;text/tab-separated-values;text/x-comma-separated-values;text/x-csv;application/vnd.oasis.opendocument.spreadsheet-flat-xml;application/vnd.ms-works;application/clarisworks;application/x-iwork-numbers-sffnumbers;application/x-starcalc;
Name=LibreOffice Calc
GenericName=Spreadsheet
Comment=Perform calculations, analyze information and manage lists in spreadsheets by using Calc.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Accounting;Stats;OpenDocument Spreadsheet;Chart;Microsoft Excel;Microsoft Works;OpenOffice Calc;ods;xls;xlsx;
InitialPreference=5
StartupWMClass=libreoffice-calc
X-KDE-Protocols=file,http,ftp,webdav,webdavs

Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Spreadsheet
Icon=document-new
Exec=libreoffice --calc
EOF

cat > /usr/share/applications/libreoffice-impress.desktop  <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
Icon=libreoffice-impress
Type=Application
Categories=Office;Presentation;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --impress %U
MimeType=application/vnd.oasis.opendocument.presentation;application/vnd.oasis.opendocument.presentation-template;application/vnd.sun.xml.impress;application/vnd.sun.xml.impress.template;application/mspowerpoint;application/vnd.ms-powerpoint;application/vnd.openxmlformats-officedocument.presentationml.presentation;application/vnd.ms-powerpoint.presentation.macroEnabled.12;application/vnd.openxmlformats-officedocument.presentationml.template;application/vnd.ms-powerpoint.template.macroEnabled.12;application/vnd.openxmlformats-officedocument.presentationml.slide;application/vnd.openxmlformats-officedocument.presentationml.slideshow;application/vnd.ms-powerpoint.slideshow.macroEnabled.12;application/vnd.oasis.opendocument.presentation-flat-xml;application/x-iwork-keynote-sffkey;
Name=LibreOffice Impress
GenericName=Presentation
Comment=Create and edit presentations for slideshows, meeting and Web pages by using Impress.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Slideshow;Slides;OpenDocument Presentation;Microsoft PowerPoint;Microsoft Works;OpenOffice Impress;odp;ppt;pptx;
InitialPreference=5
StartupWMClass=libreoffice-impress
X-KDE-Protocols=file,http,ftp,webdav,webdavs

Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Presentation
Icon=document-new
Exec=libreoffice --impress
EOF

cat > /usr/share/applications/libreoffice-draw.desktop  <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
Icon=libreoffice-draw
Type=Application
Categories=Office;FlowChart;Graphics;2DGraphics;VectorGraphics;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --draw %U
MimeType=application/vnd.oasis.opendocument.graphics;application/vnd.oasis.opendocument.graphics-flat-xml;application/vnd.oasis.opendocument.graphics-template;application/vnd.sun.xml.draw;application/vnd.sun.xml.draw.template;application/vnd.visio;application/x-wpg;application/vnd.corel-draw;application/vnd.ms-publisher;image/x-freehand;application/clarisworks;application/x-pagemaker;application/pdf;application/x-stardraw;image/x-emf;image/x-wmf;
Name=LibreOffice Draw
GenericName=Drawing Program
Comment=Create and edit drawings, flow charts and logos by using Draw.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Vector;Schema;Diagram;Layout;OpenDocument Graphics;Microsoft Publisher;Microsoft Visio;Corel Draw;cdr;odg;svg;pdf;vsd;
InitialPreference=5
StartupWMClass=libreoffice-draw
X-KDE-Protocols=file,http,ftp,webdav,webdavs

Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Drawing
Icon=document-new
Exec=libreoffice --draw
EOF

cat > /usr/share/applications/libreoffice-base.desktop  <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
Icon=libreoffice-base
Type=Application
Categories=Office;Database;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --base %U
MimeType=application/vnd.oasis.opendocument.database;application/vnd.sun.xml.base;
Name=LibreOffice Base
GenericName=Database Development
Comment=Manage databases, create queries and reports to track and manage your information by using Base.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Data;SQL;
InitialPreference=5
StartupWMClass=libreoffice-base
X-KDE-Protocols=file,http,ftp,webdav,webdavs

Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Database
Icon=document-new
Exec=libreoffice --base
EOF

cat > /usr/share/applications/libreoffice-math.desktop  <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
NoDisplay=false
Icon=libreoffice-math
Type=Application
Categories=Office;Math;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage  --math %U
MimeType=application/vnd.oasis.opendocument.formula;application/vnd.sun.xml.math;application/vnd.oasis.opendocument.formula-template;text/mathml;application/mathml+xml;
Name=LibreOffice Math
GenericName=Formula Editor
Comment=Create and edit scientific formulas and equations by using Math.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Equation;OpenDocument Formula;Formula;odf;MathML;
InitialPreference=5
StartupWMClass=libreoffice-math
X-KDE-Protocols=file,http,ftp,webdav,webdavs

Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Formula
Icon=document-new
Exec=libreoffice --math
EOF

おすすめ

転載: blog.csdn.net/weixin_44496870/article/details/131698099