Linux desktop shortcut and icon from install - linux

What do I need to add to my .spec file to create the desktop shortcut and assign an icon to the shortcut during install of my .rpm? If a script is required, an example would be very helpful.

You use a .desktop file for icons under linux. Where to put the icon depends on what distribution and what desktop environment you are using. Since I'm currently running Gnome on Fedora 9, I will answer it in those terms.
An example foo.desktop file would be:
[Desktop Entry]
Encoding=UTF-8
GenericName=Generic Piece Of Software
Name=FooBar
Exec=/usr/bin/foo.sh
Icon=foo.png
Terminal=false
Type=Application
Categories=Qt;Gnome;Applications;
The .desktop file should under Fedora 9 Gnome be located in /usr/share/applications/ , you can run a locate on .desktop to figure out where you should put in on your distro. Gnome will generally look in the KDE icon directory to see if there are other icons there also....
Encoding, Name and Exec should speak for themselves.
Generic name == Brief Description of application.
Icon == The image to display for the icon
Terminal == Is this a terminal application, should I start it as one?
Type == Type of program this is, can be used in placing the icon in a menu.
Categories == This information is what is mainly used to place the icon in a given menu if an XML file to specify such is not present. The setup for menus is handled a little differently by everyone.
There are more attributes you can set, but they aren't strictly necessary.
The image file used sits somewhere in the bowels of the /usr/share/icons/ directory. You can parse through that to find all the wonders of how such things work, but the basics are that you pick the directory for the icon type (in my case gnome) and place the image within the appropriate directory (there is a scalable directory for .svg images, and specific sizes such as 48x48 for raster images. Under Gnome all images are generally .png).

akdom has given a fairly good answer, but doesn't do its relevance justice.
Many common desktops, including Gnome, KDE and XFCE where relevant, implement the specifications laid out by freedesktop.org. Among these, is the Desktop Entry Specification which describes the format of files that define desktop icons, and Desktop Base Directory Specification that describes the locations that desktop environments should look to find these files.
Your RPM needs to include a .desktop file, as specified by the Desktop Entry Specification, and install it in the correct location as specified either by the Desktop Base Directory Specification, or in a distribution specific location (I imagine there will be aliases to use in the spec file for this location).

To create a desktop icon to an application follow the two steps below.
In an Editor create a new file.
gedit ~/.local/share/applications/NameYouWantForApplication.desktop
Place this section within the file and save it.
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=JeremysPentaho
Comment=Whatever Comment You want
Exec=/home/yourname#yourdomain.com/Source/Pentaho/data-integration/spoon.sh
Icon=/home/yourname#yourdomain.com/Source/Pentaho/data-integration/NameOfmyIconFile.jpg
Terminal=false

Related

Installed .desktop file to have user's home directory path inserted

Wording the title was a little tricky, but here's the situation. I am making a install.sh file for my game which is written in Python. I am trying to create a game folder with all assets instead of making this a module for Python. I may be doing things the hard way, but this method seems to work well.
The install.sh copies the game's directory to the HOME folder and moves a .desktop file and game's icon to the appropriate places (ie. desktop, applications folder). The issue is, this .desktop file uses Icon=~/.local/share/icons/game.png and Exec=~/Game/game.sh which causes the icon not to show up in the .desktop file or menu nor does the game shortcut execute. I replaced the ~ with $HOME and I get the same issue. However, if I change it to /home/(my account) instead of ~ or $HOME it will work perfectly and show the icon.
Is there a way to make the install bash file create this .desktop file dynamically if a user installs the game? Or is there some way of getting this to work that I am unaware of?
EDIT: Better explanation... ish.
Alternatively, put ~/.local/share/applications in the premade .desktop file, and then sed 's/~/$HOME/g' appname.desktop > $HOME/.local/share/applications/appname.desktop in the installer script, or invoke that from your language interpreter as a shell exec.
It's a real shame that more projects with GUIs don't do this. These desktop files also need a 'wmClass' element in them in order to allow for the launcher to also be a window tab. I've manually fixed several applications for my convenience this way.
Seems the easiest way was to include the files system-wide. While not my intention, it made it far easier to install all the proper files and get things works.
Putting the .desktop file in /usr/share/applications and icon file in /usr/share/icons/

Winrar Sfx get Icon from executable

i don't know if it is right to ask here but I have a really quick question.
I have an executable file which already has an icon and I plan to use winrar sfx to create a mini installer for it.
My question is: is there a way for Winrar sfx to copy the icon of my exe?
like what you do with autorun.inf, where you simple code "ICON=setup.exe" or something like that.
I know I can manually specify it on creation, but the project is still on going and it would really really save me more time.
Also I have accidentally deleted the icon for my executable. (that's the reason why I'm asking this to save me time researching how to re extract the icon.)
thanks! :D
It is not possible to use a *.exe or *.dll file containing icon resources as source for the SFX icon. The source file must be a real *.ico file with at least 1 icon. The icon file can include also several icons in various sizes like 16x16, 24x24, 32x32, 48x48, ... The functions of Windows load and display automatically the most suitable size of the icon.
There are lots of free applications which can extract icons from *.exe or *.dll files like multimedia viewer IrfanView or Resource Hacker.

How do I reveal a file as "selected" in *nix from the command line?

Is there a semi-universal mechanism by which to reveal files as selected in various *nix window managers via the command line? For example, in Windows I can say the following:
explorer.exe /select,C:\TestDir\TestFile.txt
…and Explorer will reveal the file and select it for you. In OS X I can say the following:
osascript -e 'Tell application "Finder" to reveal "MacHD:Users:myaccount:Desktop:filename.txt"'
…and it will do the same. My question is, is there any way to do the exact same thing (somewhat universally) in any of the various popular *nix flavors across window managers? Obviously "Open Containing Folder" is simple enough, but I want to go the extra step of actually opening it with the specific file selected. Any assistance is appreciated.
Best.
I don't about other file managers (other answers can add that) but for nautilus it's been recently fixed
This allows to call nautilus
uri:///path/to/file from the command
line to open uri:///path/to with file
pre-selected.
For OSX AppleScript works for all versions, but if you know you'll be dealing with 10.6 or later you'd be better served by using the -R option for "open". It's around 30 times faster.
open -R "/Volumes/Users/Desktop/file-to-open.txt"
For Linux Nautilus allows for direct calling of the file, a generic solution for GNOME (you won't find one for "Linux") is the "gnome-open" command, which currently could open the directory but won't highlight the file:
"gnome-open /tmp/file.txt"

How do I have Emacs load a font from a file?

In the interest of making my emacs setup more portable, I'd like to be able to set the current font by specifying a file rather than a font name, i.e. "Load ~/config/myfont.ttf and use size 12". Is there a way to do that in my .emacs? All the instructions I've found assume the font is already installed on the system. I'm using the XFT support on Linux, so a linux specific hack would be OK but I'd prefer something that would work on all targets.
Update: To be clear, I'm using a font that isn't standard on Windows / OS X / Linux. I'm not just looking to set a different font based on platform, but to specify a specific font file that I have (TTFs work on Windows and Linux, if not on Mac I'll get another version of the file but I still want to specify the font via file rather than name).
Unfortunately, you can't.
Emacs on different platforms uses different windowing toolkits, all of which take care of font handling for it. I don't believe you can specify a font filename in Emacs on any platform - it just doesn't work that way.
As for how to find the font:
On Linux, you could use XFT's support for a user-specific font config file which is usually ~/.fonts.conf (but check /etc/fonts/font.conf to be sure) to add whatever directory you place your fonts into.
On a Mac, you can add the font into ~/Library/Fonts. TTFs work fine on Macs, BTW.
On Windows, I think you'd just have to add it to the system fonts directory.
From there, you then go and tell Emacs (through customize or not) to use your font. You'll find the naming schemes to be different on each platform (not sure what Windows looks like), but customize should help take care of this for you - just keep a separate customize file per machine if need be.
...so basically your portable Emacs setup has to encompass more than just an Emacs config file (which, given that you're carrying a font file around, it already does).

Is it possible to call an application selection window (Right click->Open With->Other) from the linux console?

On Gnome/KDE you can select in which application you want to open file (Right click on file -> Open With -> Other). Is it possible open file that way, but from console?
For example: you print " file.ext" and instead of opening in concrete application, there are that application selection window forced and then users chooses - starts selected program.
I tried to figure out that myself, but not found anything like that.
"edit file.ext" doesn't fits my needs, because it starts preferred application and you cannot choose which. And also on my desktop it says:
"Error: no "edit" mailcap rules found for type "image/jpeg"
So, am I able to forse that "open with" window from console? If yes, can you say how?
Both on windows and mac you can do such things.
//edit at 2009-02-10 14:17
Thank you very much for answers. Command will be used in program code, so unfortunately probably I would not be able to make some extra bash scripts.
For GNOME:
gnome-open <file>
For KDE:
kfmclient exec <file>
These commands should open up the <file> in the preferred application in GNOME or KDE respectively, although I don't have an installation of either to test on.
Take a look at man run-mailcap, you can change or add selected applications for each mimetype modifying the /etc/mailcap, ~/.mailcap files and some others.
Traditionally, on Unix systens (and therefore Linux, too), you start applications from the console (and not from a UI). The command line (or console) expects you to enter the name of the application and then the filename (plus some options).
This allows to use applications (or commands) in shell scripts.
On Windows, there is no real console (the DOS box is just a reminiscence of the dark ages of MS DOS). So the MS developers came up with the idea to have the OS treat anything as a command. If it's not a real command or application, the OS will determine the file type (by extension on Windows and by some header information on Mac). For each file type, there will be an associated application in a look up table.
This is why on Windows, it appears that you can enter the name of a file on the console and you will get the application to edit that file.
If you want a quick way to fix this in the Unix console, create a script called "open" or "o" and use the file command with the option --mime to identify the file type. You can then use a case statement to launch your favorite editor.
As for the error about "mailcap rules": There is a file called "mailcap" on Unix where you can define abstract "commands" (open, edit, view, print) for file types. See the mailcap man page.

Resources