Announcement

Collapse
No announcement yet.

Desktop shortcut to command in terminal

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Desktop shortcut to command in terminal

    Hi,

    I want to ask if it is possible to create Desktop shortcut for command that needs to be run in terminal.

    For Example what i want to do is that If i press Alt+Ctrl+5 then it runs the following command in terminal without opening the terminal.

    echo 4 | sudo tee /sys/class/backlight/acpi_video0/brightness

    #2
    yes you can do this pretty easily

    Step one - Make your command a shell script, its pretty easy.

    open kate and paste in
    Code:
    #!/bin/bash
    echo 4 | sudo tee /sys/class/backlight/acpi_video0/brightness
    of course you can add any command (or commands ) the shell will take

    and save it as <fileName>.sh

    then we need to make it executable

    so find your new script in dolphin then rt.click and select "Properties" and then in the dialog switch to the Permissions tab and check "is executable".

    then you need to make an entry in your menu for this item

    1 .right click your "K" menu and select "Edit Applications"
    2. Select the sub folder for your new item then Click New Item it will then prompt for a name for this new item
    3. edit the command to <full path to script> (for example if your script is in your home folder and your user name is bob the command is /home/bob/script.sh)
    4. under the advanced tab toward the bottom you will see current shortcut key press the button next to is and then your key (or combo)
    5. save your changes to the menu

    now try your command to be sure it works. if it does not work ; first try the kmenu you made to be sure that your command is correct then check to see if your shortcut is enabled in system settings -> keyboard shortcuts -> custom shortcuts under KmenuHelper.
    Mark Your Solved Issues [SOLVED]
    (top of thread: thread tools)

    Comment


      #3
      For short one liners like that you don't even need the script just:

      Originally posted by sithlord48 View Post
      1 .right click your "K" menu and select "Edit Applications"
      2. Select the sub folder for your new item then Click New Item it will then prompt for a name for this new item
      3. edit the command to `echo 4 | sudo tee /sys/class/backlight/acpi_video0/brightness`
      4. under the advanced tab toward the bottom you will see current shortcut key press the button next to is and then your key (or combo)
      5. save your changes to the menu

      now try your command to be sure it works. if it does not work ; first try the kmenu you made to be sure that your command is correct then check to see if your shortcut is enabled in system settings -> keyboard shortcuts -> custom shortcuts under KmenuHelper.
      However, this requires root, and sudo has no terminal to ask you for a password on. It would be better to use kdesudo as that will give you a graphical prompt for your password.

      But there is probably a more elegant command... do your brightness up/down keys work? can you change the brightness in system settings? If so then you can use this dbus call instead:

      Code:
      qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement org.kde.Solid.PowerManagement.setBrightness $BRIGHTNESS
      Where $BRIGHTNESS is a number from 1 to 100. This has the advantage of it not requiring root privileges to do so you do not need to enter your password every time.

      Comment

      Working...
      X