Create executable bash script that accepts drag & drop

老子叫甜甜 提交于 2019-12-04 04:16:42
PhoneixS

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.

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

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

And the script could be something like:

#! /bin/bash

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

Try:

#!/bin/bash
mplayer "$1"

The file path of the dropped file will be passed to the script file as the 1th command line argument.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!