Sir*_*ert 8 scripts unity-dash
我最近问了这个关于向 Dash 添加 shell 脚本的问题:
在 14.04 中,如何在不打开终端的情况下运行我编写的 bash 脚本?
它工作得很好。
后续问题:如何通过 Dash 传递命令行参数?示例:在这种情况下,我的破折号命令名为“Panel”。该脚本将我的屏幕与 8 个终端面板面板。下面是一个用法示例:
panel # Tile the screen with 8 terminal windows.
panel --left # Tile the left side with 4 terminals
panel --right # Tile the right side with 4 terminals
Run Code Online (Sandbox Code Playgroud)
等等。如何像--left或--right通过 Dash传递参数?理想情况下,我想要这个工作流程:
panel --left(例如)现在它运行正确的脚本,但忽略--left.
提示?
Jac*_*ijm 16
问题是您无法.desktop从 Dash 使用参数“运行”文件,因此恐怕无法完全按照您的想法进行设置。但是,假设您的脚本确实接受参数,则有一些优雅的替代选项,甚至可能更好:
将您的脚本保存在 ~/bin
按 运行它AltF2,输入命令
<scriptname> <argument>
Run Code Online (Sandbox Code Playgroud)在 Unity 启动器中创建一个快速列表:
(假设您将脚本保存~/bin在 .

[Desktop Entry]
Name=name_of_your_script_like_you_see_it_in_Dash
Exec=<scriptname> <default_argument>
Icon=/path/to/some/icon
Type=Application
Actions=Panel;Panel -left;Panel -right;
[Desktop Action Panel]
Name=Panel
Exec=<scriptname> <default_argument>
OnlyShowIn=Unity;
[Desktop Action Panel -left]
Name=Panel -left
Exec=<scriptname> <argument_1>
OnlyShowIn=Unity;
[Desktop Action Panel -left]
Name=Panel -right
Exec=<scriptname> <argument_2>
OnlyShowIn=Unity;
Run Code Online (Sandbox Code Playgroud)
它另存为panel.desktop中~/.local/share/applications并拖动它到发射器。
创建三个不同的键盘快捷键,例如Alt+ <、Alt+ ^、Alt+>来运行您的脚本+参数:
“系统设置”>“键盘”>“快捷方式”>“自定义快捷方式”
单击“+”以添加您的命令: <scriptname> <argument>
不是最明显的,但探索选项,应该提到:你可以从 Dash 调用(zenity)选项列表:

键入选项的第一个字符,按回车键,您的脚本将使用所选参数运行。

再次假设您将脚本保存在 ~/bin 中,使其可执行并删除语言扩展,如 1.:
将下面的脚本复制到一个空文件中,另存为panel_options.sh,使其可执行。
#!/bin/bash
test=$(zenity --list "1. Panel" "2. Panel -left" "3. Panel -right" --column="Panel options" --title="Panel")
if [[ "$test" = "1. Panel"* ]]; then
<scriptname> <default_argument>
elif [[ "$test" = "2. Panel -left"* ]]; then
<scriptname> <argument_1>
elif [[ "$test" = "3. Panel -right"* ]]; then
<scriptname> <argument_2>
fi
Run Code Online (Sandbox Code Playgroud)从下面的代码创建 .desktop 文件。在Icon=线路,路径设置为你的图标,在Exec=线路的路径pane_options.sh,将其保存为panel.desktop在~/.local/share/applicatios
[Desktop Entry]
Name=Panel
Exec=/path/to/panel_options.sh
Icon=/path/to/some/icon
Type=Application
StartupWMClass=Zenity
Run Code Online (Sandbox Code Playgroud)