3

I wrote a bash script that processes a video file and I'd like to open videos into it without having to navigate to them in terminal.

$ ~/script.sh video.mp4 is how it's run in from terminal.

I've tried opening a video with gnome-terminal -e ~/home/user/script.sh but it doesn't seem to be capturing the filename/path. I'm using Nemo file manager.

I haven't been able to come up with anything while searching for solutions.

In case it's relevant, this is how I'm passing the filename argument to the script. (likely not the best way)

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

Update: I've created this .desktop file.

[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

If I drop a video file on the desktop icon, it works properly. Using "Open With" in Nemo (or Nautilus) doesn't work, though.

  • Have you tried %u or %U instead? – Tom Yan Feb 15 '16 at 12:04
  • I tried %u and it also worked. I wasn't sure of the difference between a filename with path and a url so I stuck with %f for filename. I don't think my script would appreciate being thrown multiple urls so I didn't try %U. – leetwanker Feb 16 '16 at 19:06
  • @leetwanker Do you mean with %u "Open With" works or is it only the drag and drop too? – Tom Yan Feb 16 '16 at 21:26
  • %u and %f seemed to work the same for both as far as I could tell. – leetwanker Feb 18 '16 at 5:50
  • Oh so Using "Open With" in Nemo (or Nautilus) doesn't work, though. because I had to "Reset to System Defaults" in order to add this to the list of "Recommended Applications" for .mp4 files.? – Tom Yan Feb 18 '16 at 8:06
2

I think you probably want to write a .desktop file, which can be associated to video files ("open with..."), for the bash script: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html

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

Place this file in the /usr/share/applications directory so that it is accessible by everyone, or in ~/.local/share/applications if you only wish to make it accessible to a single user.

Edit by leetwanker: Here's the .desktop file I ended up making. I'd have preferred to keep it in my own post but apparently that's frowned upon by the mods here.

I've created this fixvideo.desktop file in ~/.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;

I had to "Reset to System Defaults" in order to add this to the list of "Recommended Applications" for .mp4 files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.