2

I wanted to run a bash script with double click and I eventually found shc to do so but, despite it doing what I wanted, it needs specific permissions if transfered to another computer or if it's downloaded from a site.

Thus, my question asking for a type of file or command that's able to turn and .sh file (or any other type of file for that matter, I'm willing to re-write if necessary) without it needing to be marked as executable from the terminal with something like chmod +x <filename>.

All help on the matter appriciated, even if the solution means needing to begin from zero again.

ulovah
  • 119
  • 1
  • 13
  • Just brainstorming: .desktop files also need permissions to run on doubleclick, but any file can be run without being given execute permissions, **if** you call its interpreter from the command line, e.g. `bash file.sh` or `xdg-open file.desktop`. – wjandrea Apr 22 '17 at 00:10
  • I knew that it worked from terminal, you can even do `sh file.sh` and it works, but the problem lies in it not opening with double click so that doesn't fix it. – ulovah Apr 22 '17 at 20:57

1 Answers1

0

A definite solution depends on where you want to give the double click; on the desktop or in File Manager. Consider the following scenario, trusting you are familiar with notify-send.

Open a terminal and enter:

$ echo "notify-send 'hello world!'" > Notify

Check the file does not have x-bits:

$ ls -l Notify
-rw-rw-r-- 1 willem willem 32 apr 22 15:06 Notify

Test that it works:

$ bash Notify

Close the terminal, then start File Manager. Right click on Notify and select Open With -> Open With Other Application. Click on Use a custom command and type in bash, click on Open. You should see the "Hello world!" response.

Next double click Notify and voila!
To finish, right click on Notify -> Send to -> Desktop (Create Link). An icon appears on the desktop. Double click it...

Done !

αғsнιη
  • 35,092
  • 41
  • 129
  • 192
  • Just asking but doesn't the "open with" option only work on one system in particular, meaning that if it's transfered to another computer it won't work like it should? And I heard the "custom command" option isn't there depending on the version. Oh well, I'll go test it now and see what about it. – ulovah Apr 22 '17 at 20:54
  • There is always the possibility that the other computer uses a different OS version, window manager, file manager, etc. and that the custom command behaves differently or doesn't work. If you really want it to be so robust that it will work everywhere then you need many computers to test the command. Most of us just have 1 or 2. Let me know if you need any help or have more questions. –  Apr 22 '17 at 21:30
  • So I tested it and, as there was no custom command, it didn't work. However, if there really is a way to make it so it will work anywhere, please inform me (however minimal the information may be). I'm saying this because I've got the chance to test it on aprox 7 to 8 computers and I'll be able to adjust the script in whatever way necessary. Thanks for the info you've given me up until now :D. – ulovah Apr 22 '17 at 22:34
  • Please can you show me the script content, so I can replay it on my system? Hopefully that gives me more clues. –  Apr 25 '17 at 09:58
  • OK. But, first, let me say that this isn't actually the script that I'm working on. It is however the script I would like to change so it can always be executed with double click, no matter where. There you go: [link](https://drive.google.com/open?id=0Bx496_tbEpGwRUxyVTZBQ3RvTU0) – ulovah Apr 25 '17 at 15:33
  • Your script should run on any system with bash. My eye was drawn to your remark: "It is however the script I would like to change so it can always be executed with double click, no matter where.". You don't have to change anything INSIDE the script to make it execute on double-clicking. You can double-click on every file but it is the OS that decides what action to take. This is done through File Associations to be found the properties of a file (right-click). There you tell Ubuntu which application to start, the file as the argument. When you then double-click, Ubuntu will do just that. –  Apr 25 '17 at 20:15
  • Now there are situations where the properties of a file are automatically set. Scan programs, Image editors but also graphical text editors like Mousepad will write an output file and set the properties accordingly. In Mousepad type in some text and Save As: file.sh. The properties now are Open With Bash. –  Apr 25 '17 at 20:15
  • In contrast, when I write a script, I mostly use the vi editor in a terminal. When I save the script, I have to set the properties manually if I want to double-click. You now may have come to realize that your remark "no matter where" has depencies. There is always a chance, be it small, that the target system has altered file associations. You may have to change the properties of your script the first time on the system. –  Apr 25 '17 at 20:16
  • If you copy your script via ssh to the target, you will likely have to change the properties on command line. In this case look a xdg-mime. This is a command line tool for querying information about file type handling and adding descriptions for new file types. Unfortunately I have no experience with it. Still I hope the above is useful to you... –  Apr 25 '17 at 20:16
  • Thanks, that was very informative! That helped a lot but it's unfortunate most programs like mousepad are not installed by default. Also, I'm thinking of placing a new question as I've found a new way to explain what I want with an example, I'll put it here just in case: "I want to upload an "sh.x" file and make it so, when downloaded by another user with ubuntu, it saves with the 'execute as a program' option automatically. How would I go about that?" – ulovah Apr 25 '17 at 21:53
  • I'm aware that's not what this thread was about. However, what I want is essentially get a file to be executable when transferred or downloaded on to the system. I came up with that example because I realised it would make the script I sent you unnecessary because sh.x files are double-clickable by default (they are not executable by default though) and I can easily convert my sh script to one of those. Well, thanks for all the help until now, I learnt a lot :D – ulovah Apr 25 '17 at 22:00
  • I think you don't understand me. All files you see on your Desktop of in a file manager like Nautilus or Thunar can be double-clicked. What happens next depends on what application that file is associated with. The file extension only makes the type of file more "recognizable" to us humans. Linux does care what extension a file has or no extension at all. By the way, the extension sh.x is not a common one as far as I know. –  Apr 25 '17 at 22:45
  • Maybe I didn't specify enough: I would like to use the sh.x file (the way it's opened by default, not the extension) because you can only open it by marking it executable and double clicking. Basically, I'm saying it would be best to use the type of file sh.x is associated with, so there are (at least no "mess-ups" in how to open it (for example opening it with an editor will give you corrupt valors, so yeah). – ulovah Apr 26 '17 at 12:06
  • Ulovah, I feel I cannot give you any more/better advice than I already did. I can only suggest you go ahead and try the solution that you have in mind. If that works, then all is well for you. If not, feel free to ask another question to the forum so somebody else can pick it up. Sorry I was unable to help you to a final solution. –  Apr 26 '17 at 12:16
  • No problem! And thank you because, had you not provided some more specific information on how to possible do it, I would've never stumbled upon the idea I now have in mind. Really, thanks for all the suggestions :) – ulovah Apr 26 '17 at 16:39