{"id":88,"date":"2025-03-16T10:02:56","date_gmt":"2025-03-16T09:02:56","guid":{"rendered":"https:\/\/linuxundich.de\/en\/?p=88"},"modified":"2026-10-03T23:04:47","modified_gmt":"2026-10-03T21:04:47","slug":"custom-nautilus-scripts-convert-images-to-webp","status":"publish","type":"post","link":"https:\/\/linuxundich.de\/en\/custom-nautilus-scripts-convert-images-to-webp\/","title":{"rendered":"Custom Nautilus scripts: Convert images to WebP"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I use the GNOME desktop every day and appreciate its minimalist design. Still, some features are missing that could make my workflow more efficient, like running certain tasks straight from the file manager with a single click. Nautilus scripts make that easy to fix.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, I&#8217;ll show you how to create such a script. As an example, I want to demonstrate how to convert images to WebP without having to open an image editor. For that, I use <code>cwebp<\/code>, a powerful tool for converting images to the WebP format, and Zenity to provide a graphical dialog for entering image sizes.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video controls src=\"https:\/\/linuxundich.de\/wp-content\/uploads\/2025\/03\/ConvertToWebP.webm\"><\/video><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"warum-webp\">Why WebP?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">WebP is a modern image format that compresses better than JPG or PNG without noticeably hurting image quality. It is especially useful for web developers and bloggers, since it reduces page load times and improves performance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"vorbereitung-ben\u00f6tigte-pakete-installieren\">Preparation: Installing the required packages<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before you start with the script, make sure the required programs are installed. If they aren&#8217;t, you can install them on Debian-based distributions like Ubuntu or TUXEDO OS with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>### Unter Arch Linux, Manjaro und Co.\n$ &lt;strong&gt;sudo pacman -S libwebp zenity&lt;\/strong&gt;\n### Unter Ubuntu, Debian und Co.\n$ &lt;strong&gt;sudo apt install webp zenity&lt;\/strong&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"erstellung-des-skripts-zur-webp-konvertierung\">Creating the WebP conversion script<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new script in the Nautilus scripts folder:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ &lt;strong&gt;mkdir -p ~\/.local\/share\/nautilus\/scripts&lt;\/strong&gt;\n$ &lt;strong&gt;gedit ~\/.local\/share\/nautilus\/scripts\/ConvertToWebP&lt;\/strong&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now paste the following code into the file and save it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# \u00dcberpr\u00fcfen, ob cwebp und zenity installiert sind\nif ! command -v cwebp &amp;&gt; \/dev\/null; then\n    zenity --error --text=&quot;cwebp ist nicht installiert.&quot;\n    exit 1\nfi\n\n# Benutzer nach Breite und H\u00f6he fragen\ninput=$(zenity --forms --title=&quot;Bildkonvertierung nach WebP&quot; \n    --text=&quot;Gebt die gew\u00fcnschte Breite und H\u00f6he ein (0 f\u00fcr Originalgr\u00f6\u00dfe):&quot; \n    --add-entry=&quot;Breite&quot; \n    --add-entry=&quot;H\u00f6he&quot;)\n\n# Falls der Benutzer abbricht, das Skript beenden\nif &amp;#91; -z &quot;$input&quot; ]; then\n    exit 1\nfi\n\nwidth=$(echo &quot;$input&quot; | cut -d '|' -f1)\nheight=$(echo &quot;$input&quot; | cut -d '|' -f2)\n\n# Falls keine Werte eingegeben wurden, Standardwerte setzen\nwidth=${width:-0}\nheight=${height:-0}\n\n# Alle ausgew\u00e4hlten Dateien verarbeiten\nfor file in &quot;$@&quot;; do\n    if &amp;#91; -f &quot;$file&quot; ]; then\n        output=&quot;${file%.*}.webp&quot;\n        \n        if &amp;#91;&amp;#91; &quot;$width&quot; -eq 0 &amp;&amp; &quot;$height&quot; -eq 0 ]]; then\n            # Keine Skalierung, direkt konvertieren\n            cwebp &quot;$file&quot; -o &quot;${file%.*}.webp&quot; &gt;\/dev\/null 2&gt;&amp;1\n        else\n            cwebp -resize &quot;$width&quot; &quot;$height&quot; &quot;$file&quot; -o &quot;${file%.*}.webp&quot; &gt;\/dev\/null 2&gt;&amp;1\n        fi\n    fi\ndone<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rechte-setzen\">Setting permissions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For the script to run, it has to be marked as executable. You do that with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ &lt;strong&gt;chmod +x ~\/.local\/share\/nautilus\/scripts\/ConvertToWebP&lt;\/strong&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"skript-in-nautilus-einbinden\">Using the script in Nautilus<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Once the script is created, it is available right away in the Nautilus file manager. Select one or more images, right-click them, go to <em>Scripts<\/em>, and choose <em>ConvertToWebP<\/em>.<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6ac2f6fb06e85&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6ac2f6fb06e85\" class=\"wp-block-image wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/linuxundich.de\/wp-content\/uploads\/2025\/03\/nautilus-skripte-ConvertToWebP1.webp\" alt=\"The script shows up in the Scripts menu of the Nautilus file manager right after you save it.\" style=\"width:100%\"\/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\">The script shows up in the Scripts menu of the Nautilus file manager right after you save it.<\/figcaption><\/figure>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6ac2f6fb080e5&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6ac2f6fb080e5\" class=\"wp-block-image wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/linuxundich.de\/wp-content\/uploads\/2025\/03\/nautilus-skripte-ConvertToWebP2.webp\" alt=\"Zenity asks for the target image size. If the size should stay the same, leave the fields empty or enter 0.\" style=\"width:100%\"\/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\">Zenity asks for the target image size. If the size should stay the same, leave the fields empty or enter 0.<\/figcaption><\/figure>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6ac2f6fb084f4&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6ac2f6fb084f4\" class=\"wp-block-image wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/linuxundich.de\/wp-content\/uploads\/2025\/03\/nautilus-skripte-ConvertToWebP3.webp\" alt=\"Converted to WebP, the images are only 1\/10 to 1\/20 of their original file size at the same dimensions.\" style=\"width:100%\"\/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\">Converted to WebP, the images are only 1\/10 to 1\/20 of their original file size at the same dimensions.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The script now converts all selected image files in common formats to WebP and reduces their size while keeping the aspect ratio. If <code>cwebp<\/code> is not installed, it shows an error message. Alternatively, you can enter the target width and height in pixels.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nautilus scripts can make your GNOME desktop a lot more efficient. This example lets you convert images to WebP right in the file manager, without opening a separate image editor.<\/p>\n","protected":false},"author":2,"featured_media":87,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"lui_source_id":44190,"lui_source_hash":"2efe8ed50b8674bed7fc64f476e711299847fd9702d08c037ffa2b43575ada45","lui_source_translated":"2026-10-03","lui_source_reviewed":true,"lui_via_url":"","lui_via_label":"","lui_source_url":"","lui_source_label":"","footnotes":""},"categories":[2],"tags":[],"class_list":["post-88","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gnu-linux"],"_links":{"self":[{"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/posts\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/comments?post=88"}],"version-history":[{"count":1,"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/posts\/88\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/posts\/88\/revisions\/113"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/media\/87"}],"wp:attachment":[{"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/media?parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/categories?post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxundich.de\/en\/wp-json\/wp\/v2\/tags?post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}