I've created a script to empty my trash. I want to be able to execute it without having to use the terminal. Is there anyway I could do this?
-
Run `chmod +x
`, if not done already. Then you will be asked whether to run the script when double clicking it, at least in Nautilus. But where's the point, when you can simply right click on your trash and tell it to empty itself? – s3lph Nov 16 '15 at 23:34 -
Right clicking doesn't work for me. Sometimes files and folders get left over that refuse to be deleted. – draoi Nov 16 '15 at 23:35
-
When I double click, it opens the file in gedit. – draoi Nov 16 '15 at 23:36
-
If you make a .desktop file it can also be added to the launcher. Do you want me to write up an answer on how to do it? – TheWanderer Nov 16 '15 at 23:38
-
I'm gonna try changing it to a .desktop file. – draoi Nov 16 '15 at 23:39
-
@muru dconf-editor doesn't for me. – draoi Nov 16 '15 at 23:42
-
@Zacharee1 That would be great. – draoi Nov 16 '15 at 23:42
-
OK. I'll write one. Give me a bit. – TheWanderer Nov 16 '15 at 23:43
-
Or http://askubuntu.com/questions/286621/how-do-i-run-executable-scripts-in-nautilus – muru Nov 16 '15 at 23:43
-
Menu bar? Nautilus doesn't appear to have a menu bar. – draoi Nov 16 '15 at 23:45
-
I see it now... – draoi Nov 16 '15 at 23:46
-
It works now, thanks. Apparently the default behavior is a bug. – draoi Nov 16 '15 at 23:51
-
You're holding back. Show us the script. ;-) – SDsolar Jul 29 '17 at 06:51
1 Answers
A nice way to execute scripts by double clicking them is to make a .desktop file, which is essentially a shortcut. Aside from scripts, it can execute pretty much any executable, including .jar. Here's how to make one:
- Create a file and name it
<program name>.desktop Open it with GEdit and paste this text in:
[Desktop Entry] Version=1.0 Type=Application Name=<whatever you want the file name to be> Comment=<description of program> Exec=</path/to/script> Icon=</path/to/optional/icon.png>Edit the Name, Comment, Exec, and Icon fields to what you want. Having an Icon is optional and you can simply remove that line if you don't want to have one. Make sure to delete the surrounding
<>.Save the file and then go into its properties.
Go to Permissions and mark it as executable.
You should now be able to double click this file and it will execute your script. If you don't want a terminal window to be shown, add Terminal=false to the file. You can now add this file to the launcher for easy access, if you like. If you want to move your script, you'll have to update the Exec path in the .desktop file.
Any problems, just comment.
---Update---
Thanks to @kos, I now know the solution to your problem. Instead of having sudo rm -rf ~/.local/share/Trash/*, you want just rm -rf ~/.local/share/Trash/*. Since ~/.local/share/Trash is owned by you, you can do anything from your user account to edit it without sudo. After testing the non-sudo command out, I can confirm that it works.
- 19,315
- 12
- 49
- 65
-
It says there was an error launching the application.[Desktop Entry] Version=1.0 Type=Application Name=
Comment= – draoi Nov 17 '15 at 00:02Exec=<./empty_trash.sh> Icon= -
-
A window comes up and says "There was an error launching the application." – draoi Nov 17 '15 at 00:04
-
-
-
-
-
-
[Desktop Entry] Version=1.0 Type=Application Name=
Comment= – draoi Nov 17 '15 at 00:07Exec=<./empty_trash.sh> Icon= -
Yeah, take away the `<>` from around the paths, name and comment. Those were to denote that what was inside should be changed. – TheWanderer Nov 17 '15 at 00:08
-
-
-
Under `Exec` you can't have `./` since that's the working directory. If the script is in your home directory, change that to `~/`, although a definite path might be better. – TheWanderer Nov 17 '15 at 00:11
-
-
-
-
Add `Terminal=true` to it and see what happens. What's the command that you're running? – TheWanderer Nov 17 '15 at 00:18
-
-
-
So you double-clicked the desktop file but nothing happened (the trash didn't empty)? I would say just add the command to the Exec field. You'll have to enter your password when you double click it. – TheWanderer Nov 17 '15 at 00:20
-
The trash doesn't empty, and the terminal doesn't open for me to enter my password. Clicking on the script itself works, but naturally it would be nicer to get it working with a .desktop icon. – draoi Nov 17 '15 at 00:22
-
-
[Desktop Entry] Version=1.0 Type=Application Name=trashx Exec=sudo rm -rf ~/.local/share/Trash/* Terminal=True – draoi Nov 17 '15 at 00:23
-
-
Now that causes the error message to pop back up. I've got to go to sleep now, but this has been interesting. I'm going to look into this further when I have more energy. I like the idea I've being able to make a desktop icon for a little script, also so that I could run other programs that I usually have to start with the terminal. – draoi Nov 17 '15 at 00:30
-
It is a great feature. I'll reboot into Ubuntu in a bit and update my answer if I'm able to come up with anything. – TheWanderer Nov 17 '15 at 00:35
-
Thanks to @kos, I now know that `sudo` is unnecessary for this command. Putting `rm -rf ~/.local/share/Trash`instead fixed it. – TheWanderer Nov 17 '15 at 00:49
-
As a .desktop file, it's still not working. As an sh file, it works without the sudo command. However I'm afraid that if I delete a locked file, it will only work with the sudo command. – draoi Nov 18 '15 at 09:34
-
The original problem was that the normal method of emptying the trash did not work after I had deleted a large folder, possibly because it was locked. http://askubuntu.com/questions/698920/ubuntus-terrible-trash/698922?noredirect=1#comment1023841_698922 – draoi Nov 18 '15 at 09:37
-
It's kind of dangerous, but what if you put a `chmod 777` on the stuff inside the Trash folder before you run the delete command. – TheWanderer Nov 18 '15 at 11:01