1

Unsuccessfully creating a .desktop file. In usr/share/applications user has r+w permissions. Do I need to change to rwx to create viable .desktop?

sudo chmod u+x for my user is not working (lacking operand after 'u+x').

Tried Freedesktop but it doesn't seem to cover this aspect...

Permissions are not my strong suit and I am new... very frustrated.

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Foo
Comment=FooApp
Exec=/usr/share/applications/simi1.py
Icon=/usr/share/icons/hicolor/48x48/apps/pic.png
Terminal=true
StartupNotify=false

Idu how this is possible...my file is clearly in the dir

screenshot of error and file ls info

meyeti
  • 59
  • 1
  • 5

2 Answers2

0

By default root should be the owner of the /usr/share/applications directory.

Are you able to use sudo to create and edit the file?

Either at a console :

sudo nano /usr/share/applications/myApp.desktop

Or maybe :

sudo gedit

then write the file and save it to the directory.

It is best practice to use sudo to make/edit files in directories with root permissions rather than change these permissions.

Alternatively, you could write the file in your home directory then use sudo to copy it to /usr/share/applications

sudo cp myApp.desktop /usr/share/applications/

Finally, if you want to use this myApp.desktop file as a shortcut on your desktop simply :

cp /usr/share/applications/myApp.desktop ~/Desktop/
  • yes I was able to cp to applications after writing with a text file...is this all that is necessary? But how do I get the .desktop file (now residing in usr/../applications onto my desktop? – meyeti Jan 25 '18 at 05:20
  • cp /usr/share/applications/myApp.desktop ~/Desktop/ – TelamonAegisthus Jan 25 '18 at 06:30
  • what's the pt? I experimented....changed Name and the filename (saved properly ^O) I ls -t and got the old file name showing up....I want to break my freaking machine at this pt. srsly so whenever I write a .desktop into usr/../applications I can't edit or delete the file??? – meyeti Jan 25 '18 at 06:43
  • well I got it on the desktop...now it's missing the icon image and tells me it's untrusted.... – meyeti Jan 25 '18 at 06:52
  • apparently this is a artful aardvark bug ... ? https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/1687179 – meyeti Jan 25 '18 at 07:10
  • In case it interests you I'll just link a few articles on icon files ( in order of most useful to you ) : https://askubuntu.com/a/722182/733893 https://developer.gnome.org/integration-guide/stable/icons.html.en https://askubuntu.com/a/435612/733893 Best of luck, and let me know how you go with getting icons working. – TelamonAegisthus Jan 25 '18 at 07:21
0

First, you need to have root privileges to do this. Second you don't need executable permissions on the files in /usr/share/applications. A simple ls -l on the directory on my own machine shows this:

$ ls -l
total 2864
-rw-r--r-- 1 root root  5511 Dec 19 08:14 alacarte.desktop
-rw-r--r-- 1 root root  3417 Dec 17 15:21 assistant-qt5.desktop
-rw-r--r-- 1 root root 14329 Jan 23 13:37 bamf-2.index
-rw-r--r-- 1 root root   296 Nov  2  2015 bastet.desktop
-rw-r--r-- 1 root root  6305 Jan 16  2017 bleachbit.desktop
-rw-r--r-- 1 root root  6333 Aug 30 13:38 bleachbit-root.desktop
...

Note that none of the above files are executable; in other words, files which are present in application directories like /usr/share/applications or ~/.local/share/applications are not executable because no one is going to execute them. Files in your Desktop folder are executable so you can execute them but no one goes in /usr/share/applications to run an application.

Let's solve the first problem:

You can become root by running sudo -i and then entering your user password. Once you are root, you can create the desktop file with either

# gedit /usr/share/applications/[file].desktop

Or

# nano /usr/share/applications/[file].desktop

Now you can enter the contents of the file as you desire.

hexman
  • 881
  • yes navigated through this...I have file.desktop saved in usr/../applications (I obv can't really edit it here) but the icon is not on my desktop anymore... – meyeti Jan 25 '18 at 05:32
  • @meyeti Desktop icons are fetched from your ~/Desktop folder not /usr/share/applications. Besides, what's preventing you from running sudo -i and then editing with gedit? – hexman Jan 25 '18 at 05:35
  • no protocol specified... – meyeti Jan 25 '18 at 05:43
  • @meyeti Can you run nano /usr/share/applications/[FILE] instead of gedit? – hexman Jan 25 '18 at 05:46
  • i can get in...I'm denied permissions to save changes (so ^X then Y isn't viable) only ^Y then N to exit – meyeti Jan 25 '18 at 05:52
  • @meyeti You need to run nano as root (sudo nano ... should work) and use ^O to save the file. You can also put the .desktop file in ~/.local/share/applications instead as that doesn't require any additional privileges. – hexman Jan 25 '18 at 05:54
  • yup figured it was sudo -i ...that works (it clears the contents tho but I copy/pasted). I prefer usr/../applications for now tho but what about the 'substance' of the script I have Exec,Path,Icon,terminal variables in place but no file on my desktop to test run... – meyeti Jan 25 '18 at 05:56
  • @meyeti Check this stackexchange question for the protocol error: https://unix.stackexchange.com/a/10441/264220. If you're on Wayland then switch to X as it doesn't allow for running GUI apps as root. If your issue is solved then close the question (and perhaps list the steps you took). – hexman Jan 25 '18 at 06:00
  • protocol err was solved. it's 1) usr/../applications 2)sudo -i 3)nano file.desktop U can't combine commands.... Now that that's out of the way, I'm still left with no 'tangible' file to run from my desktop... – meyeti Jan 25 '18 at 06:08
  • wtf $ nano file1.desktop doesn't even show up in usr/share/applications ls -t srsly I am soooo frustrated omg – meyeti Jan 25 '18 at 06:39