Ubuntu – How to pass command line arguments to a script through Dash? (14.04)

scriptsunity-dash

I recently asked this question about adding a shell script to Dash:

In 14.04 how do I run a bash script I wrote without opening a terminal?

It worked perfectly.

Follow-up question: How can I pass command-line arguments through Dash? Example: In this case, my dash command is named "Panel". The script panels my screen with 8 terminals. Here's an example of the usage:

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

And so on. How can I pass arguments like --left or --right through Dash? Ideally I'd like to have this workflow:

  • Press the SUPER key
  • Type panel --left (for example)
  • Dash goes away and the left side is paneled.

Right now it runs the right script, but ignores --left.

Tips?

Best Answer

The problem is that you cannot "run" a .desktop file from Dash with arguments, so the setup exactly like you have in mind is impossible I am afraid. However, assuming your script does take arguments, there are a few elegant alternative options, maybe even better:


  1. Save your script in ~/bin

    • remove the extension
    • make it executable
    • run it by pressing AltF2, type the command

      <scriptname> <argument> 
      

  1. Create a quicklist in the Unity launcher:

    (assuming you saved the script in ~/bin, made it executable and removed the extension as in 1.)

    enter image description here

    [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;
    

    Save it as panel.desktop in ~/.local/share/applications and drag it on to the launcher.


  1. Create three different keyboard shortcuts, for example Alt+<, Alt+^, Alt+> to run your script+arguments:

    "System Settings" > "Keyboard" > "Shortcuts" > "Custom Shortcuts"

    Click "+" to add your commands: <scriptname> <argument>


  1. Not the most obvious one, but exploring the options, it should be mentioned: you can call a (zenity) option list from Dash:

    enter image description here

    Type the first character of your option, press return and your script will run with the chosen argument.

    enter image description here

    Again assuming that you saved the script in ~/bin, made it executable and removed the language extension as in 1.:

    • Copy the script below into an empty file, save it as panel_options.sh, make it executable.

      #!/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
      
    • Create the .desktop file from the code below. In the Icon= line, set the path to your icon, in the Exec= line the path to pane_options.sh, save it as panel.desktop in ~/.local/share/applicatios

      [Desktop Entry]
      Name=Panel
      Exec=/path/to/panel_options.sh
      Icon=/path/to/some/icon
      Type=Application
      StartupWMClass=Zenity