使用 gnome 中的 bash 脚本打开文件

使用 gnome 中的 bash 脚本打开文件

我编写了一个处理视频文件的 bash 脚本,我想在其中打开视频而不需要在终端中导航到它们。

$ ~/script.sh video.mp4是如何从终端运行的。

我尝试打开视频,gnome-terminal -e ~/home/user/script.sh但它似乎无法捕获文件名/路径。我正在使用 Nemo 文件管理器。

在寻找解决方案时我还没有想出任何东西。

如果相关的话,这就是我将文件名参数传递给脚本的方式。(可能不是最好的方法)

#!/bin/bash
args=("$@")
in_file=${args[0]}

更新:我已经创建了这个.desktop 文件。

[Desktop Entry]
Comment=
Terminal=true
Name=fixvideo
Exec=/home/user/fixvideo.sh %f
Type=Application
Icon=/usr/share/icons/gnome/48x48/apps/gnome-settings-theme.png
Encoding=UTF-8

如果我将视频文件拖放到桌面图标上,它就可以正常工作。但是使用 Nemo(或 Nautilus)中的“打开方式”不起作用。

答案1

我认为您可能想要为 bash 脚本编写一个 .desktop 文件,该文件可以与视频文件关联(“打开方式...”): https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html

https://developer.gnome.org/integration-guide/stable/desktop-files.html.en

将此文件放在 /usr/share/applications 目录中,以便每个人都可以访问,或者,如果只希望单个用户可以访问,则放在 ~/.local/share/applications 中。

由 leetwanker 编辑: 这是我最终制作的 .desktop 文件。我本来希望将其保留在自己的帖子中,但显然这里的管理员不赞成这样做。

我已经在~/.local/share/applications/

[Desktop Entry]
Comment=
Terminal=true
Name=fixvideo
Exec=/home/user/fixvideo.sh %f
Type=Application
Icon=/usr/share/icons/gnome/48x48/apps/gnome-settings-theme.png
Encoding=UTF-8
Hidden=false
NoDisplay=false
Categories=AudioVideo;Player;Recorder;
MimeType=video/dv;video/mpeg;video/x-mpeg;video/msvideo;video/quicktime;video/x-anim;video/x-avi;video/x-ms-asf;video/x-ms-wmv;video/x-msvideo;video/x-nsv;video/x-flc;video/x-fli;video/x-flv;video/vnd.rn-realvideo;video/mp4;application/mp4;video/mp4v-es;video/mp2t;application/ogg;application/x-ogg;video/x-ogm+ogg;audio/x-vorbis+ogg;audio/ogg;video/ogg;application/x-matroska;audio/x-matroska;video/x-matroska;video/webm;audio/webm;audio/x-mp3;audio/x-mpeg;audio/mpeg;audio/x-wav;audio/x-mpegurl;audio/x-scpls;audio/x-m4a;audio/x-ms-asf;audio/x-ms-asx;audio/x-ms-wax;application/vnd.rn-realmedia;audio/x-real-audio;audio/x-pn-realaudio;application/x-flac;audio/x-flac;application/x-shockwave-flash;misc/ultravox;audio/vnd.rn-realaudio;audio/x-pn-aiff;audio/x-pn-au;audio/x-pn-wav;audio/x-pn-windows-acm;image/vnd.rn-realpix;audio/x-pn-realaudio-plugin;application/x-extension-mp4;audio/mp4;audio/amr;audio/amr-wb;x-content/video-vcd;x-content/video-svcd;x-content/video-dvd;x-content/audio-cdda;x-content/audio-player;application/xspf+xml;x-scheme-handler/mms;x-scheme-handler/rtmp;x-scheme-handler/rtsp;

我必须“重置为系统默认值”才能将其添加到 .mp4 文件的“推荐应用程序”列表中。

相关内容