Creating a Custom Application Launcher with Quicklist
Application launchers that you see in the main menu of your desktop environment are configured using .desktop files. These .desktop files contains code adhering to standards specified by freedesktop specifications.
To create a custom application launcher with quicklist, it is important to understand the structure of a .desktop file first. This article will list only those options that are essential for creating a simple custom application launcher. However, .desktop files are really powerful and it is possible to create advanced launchers with hundreds of options that includes language specific strings, desktop environment restrictions, keyword tags and so on.
The example below shows a custom application launcher called “Text Editors” having two actions in a quicklist:
Name=Text Editors
Comment=My Favorite Text Editors
Version=1.0.0
Exec=
Terminal=false
Type=Application
StartupNotify=true
Icon=gedit
Actions=Sublime-Text;Gedit;
[Desktop Action Sublime-Text]
Name=Sublime Text
Exec=subl %U
StartupNotify=true
[Desktop Action Gedit]
Name=Gedit
Exec=gedit %U
StartupNotify=true
Where:
- Name is the name of your custom application launcher that will be shown in the main menu
- Comment is the searchable short description for the custom launcher
- Version is the user specified version for the custom app launcher
- Exec is the default command to run when you left click on the icon of the custom app launcher
- Terminal defines whether to run the command in a terminal or not
- Type specifies the type of application
- StartupNotify, if set to true, allows the system to track launcher events and actions (example: cursor changes to an hourglass figure when doing some background work)
- Icon refers to the name of the icon to be used for the custom application launcher (read note below)
- Actions specify the order items in a quicklist
- [Desktop Action XXXX] creates a new quick list entry that uses some of the options explained above
So to create a valid .desktop launcher with quicklist, you must have a broad [Desktop Entry] category first, followed by [Desktop Action XXXX] entries that define the behavior of individual actions in a quicklist. It is necessary that you use all the variables explained above, as they are the bare minimum ones required for a functional .desktop file.
Note that you have to correctly specify the icon name so that the system can automatically pick an icon for your custom launcher. It is possible to use your own icon file, but for the sake of consistency and reducing dependencies for the custom launcher, it is recommended to use icons already included in you distributions.
To see all valid icon names, run the command below in a terminal:
To save all valid icon names in a text file, run the command below in a terminal:
sed 's/.png//g' > icon_names.txt
To activate a .desktop application launcher with quicklist, you need to save it at appropriate location. Run the commands below to create the required .desktop file:
$ subl text-editors.desktop
Replace “subl” with the command of your favorite text editor. Paste the code from above or use your own code, make the file executable using the command below:
All quicklists can now be accessed by right clicking on the custom application launcher icon. Here is what the end result looks like with an application launcher created from the code above:
Creating a Screenshot Application Using Custom Launcher and Quicklists Only
As you can define left click and right click actions of any custom launcher, it is possible to create minimal apps without much code and GUI interface. Check out an example of a screenshot app made using quicklists only.
To begin with, you have to install some dependencies for the screenshot app to work:
Create a new .desktop file:
$ subl screenshot-app.desktop
Paste the code below in screenshot-app.desktop file:
Name=The Screenshot App
Comment=Take screenshots of your desktop
Version=1.0.0
Exec=bash -c 'import -window root ~/Pictures/"$(date -Is)".png'
Terminal=false
Type=Application
StartupNotify=true
Icon=camera
Actions=Fullscreen-delayed;Focused-delayed;Focused;Select-window;
[Desktop Action Fullscreen-delayed]
Name=Grab Fullscreen After 5 Seconds Delay
Exec=bash -c 'sleep 5; import -window root ~/Pictures/"$(date -Is)".png'
StartupNotify=false
[Desktop Action Focused-delayed]
Name=Grab Focused Window After 5 Seconds
Exec=bash -c 'window=$(xdotool getwindowfocus); sleep 5; import -window
"$window" ~/Pictures/"$(date -Is)".png'
StartupNotify=false
[Desktop Action Focused]
Name=Grab Focused Window
Exec=bash -c 'window=$(xdotool getwindowfocus); import
-window "$window" ~/Pictures/"$(date -Is)".png'
StartupNotify=false
[Desktop Action Select-window]
Name=Select Window to Capture
Exec=bash -c 'import ~/Pictures/"$(date -Is)".png'
StartupNotify=false
Save the file and make it executable:
Now whenever you click on “The Screenshot App”, it will capture a full screen screenshot and store it in ~/Pictures directory. More options are available when you right click on the app icon.
Conclusion
Creating custom launchers with quicklists is a great way to access commonly used apps and commands. As these app launchers work like any other desktop application, it is possible to pin them on taskbar or panel available in your desktop environment. If you keep dependencies minimal, these launchers are quite portable and can be shared between different systems.
from Linux Hint https://ift.tt/2FHFakh
0 Comments