创建接受拖动 & 的可执行 bash 脚本降低 [英] Create executable bash script that accepts drag & drop

查看:23
本文介绍了创建接受拖动 & 的可执行 bash 脚本降低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Ubuntu 上从源代码编译了 mplayer.我不想使用 GUI,但我想制作一个可执行的 bash 文件,该文件从拖放到 bash 文件中的文件中获取路径.我怎样才能让这样的事情成为可能?

I compiled mplayer from source on Ubuntu. I didn't want to use a GUI but I wanted to make a executable bash file that gets the path from an file that gets dropped onto the bash file. How do I make such a thing possible?

我想让它看起来像这样:mplayer <获取文件的完整路径.file-ending>

I wanted to make it look something like this: mplayer <get full path to file.file-ending>

我希望可执行的 bash 文件放在我的桌面上;)

I want the executable bash file to sit on my desktop ;)

如果可能的话,我想要一个 rightclick ->从mplayer开始功能,但我不知道如何制作.

If possible, I'd just like an rightclick -> start with mplayer function, but I don't know how to make one.

推荐答案

您可以使用 $1 访问传递给脚本的参数(对于第一个参数).您还应该制作一个 .desktop 文件,以便 Nautilus(或您的桌面管理器)知道该做什么并使用 %u 将放置的路径传递给脚本.

You can access arguments passed to the script with $1 (for the first argument). And also you should make a .desktop file so Nautilus (or your desktop manager) know what to do and use %u to pass the dropped path to the script.

例如,您可以创建一个名为 DropOverMe.desktop 的文件:

For example you can create a file named DropOverMe.desktop:

[Desktop Entry]
Encoding=UTF-8
Name=Drop Over Me
Comment=Execute the script with the file dropped
Exec=gnome-terminal -e "/folder/to/the/script/launchme.sh "%u""
Icon=utilities-terminal
Type=Application

我使用 gnome-terminal,因为我的 PC 上有 Ubuntu,请使用您喜欢的终端应用程序.

I use gnome-terminal as I have Ubuntu on my PC, use your preferred terminal application.

脚本可能是这样的:

#! /bin/bash

echo "Launched with $1" >> /tmp/history.log

这篇关于创建接受拖动 &amp; 的可执行 bash 脚本降低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆