This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Script double-click behavior for other extensions?

Tags: None
(comma "," separated)
ba1po
Registered Member
Posts
5
Karma
0
OS
Hello

I have a question regarding the "service" that detects the execution of a script.
When you try to open a bash script in dolphin, it asks you whether you want to execute it or edit it.
For example: https://drive.google.com/open?id=15rUWyXJcYG7UtLkUiAotLSnPN0Jqi9To

Is there a way I can mimic the same behavior but for another extension, say sql files to be edited or executed?

Thank you in advance!
airdrik
Registered Member
Posts
1854
Karma
5
OS
It may be going based on the file starting with what's called a shebang line that looks like: #!/usr/bin/bash which indicates what executable should be used to run the script. You could try that with sql fles, though that probably wouldn't work due to the #! pair needing to be the first two characters in the file and # not being a sql comment character.

If it were me, I'd set up the file associations for the .sql file type with both the Edit and Execute applications, moving whichever you prefer to be the default to the top and then use the right-click menu to select the other.


airdrik, proud to be a member of KDE forums since 2008-Dec.
ba1po
Registered Member
Posts
5
Karma
0
OS
airdrik wrote:It may be going based on the file starting with what's called a shebang line that looks like: #!/usr/bin/bash which indicates what executable should be used to run the script. You could try that with sql fles, though that probably wouldn't work due to the #! pair needing to be the first two characters in the file and # not being a sql comment character.

If it were me, I'd set up the file associations for the .sql file type with both the Edit and Execute applications, moving whichever you prefer to be the default to the top and then use the right-click menu to select the other.


Thanks for your answer!

The shebang line is not responsible for this
With .desktop files, for example, one can also be asked if file should be edited or executed.

I also thought of the file association solution, but I would like to have the same behaviour as executable files.
airdrik
Registered Member
Posts
1854
Karma
5
OS
So .desktop files are special as they are recognized by the desktop as having metadata about some application, including how to invoke it; so the desktop knows that when you click on it you just want to run the application (or ask to edit or execute if the confirmation option for Executing scripts or desktop files is enabled).
Other executable files are recognized as being executable by having the executable permission set; but that only works if either the file is an actual compiled executable file or the file has the shebang line to tell the system what interpreter to use to execute it (same thing would be expected to happen if you tried to run the file from a console, except that clicking on it in dolphin doesn't show you any output from running it).
Other non-executable files are opened using the top application selected in the file association selection.


airdrik, proud to be a member of KDE forums since 2008-Dec.
ba1po
Registered Member
Posts
5
Karma
0
OS
airdrik wrote:So .desktop files are special as they are recognized by the desktop as having metadata about some application, including how to invoke it; so the desktop knows that when you click on it you just want to run the application (or ask to edit or execute if the confirmation option for Executing scripts or desktop files is enabled).
Other executable files are recognized as being executable by having the executable permission set; but that only works if either the file is an actual compiled executable file or the file has the shebang line to tell the system what interpreter to use to execute it (same thing would be expected to happen if you tried to run the file from a console, except that clicking on it in dolphin doesn't show you any output from running it).
Other non-executable files are opened using the top application selected in the file association selection.


Thanks again for your answer.

:| Exactly, that's what I want to do, tell the desktop to behave the same way (ask if open or execute) for sql files.
When you say desktop, you mean what?
Because konqueror does not show this behaviour, it's only dolphin.
So I'm guessing this behaviour is embedded in dolphin's code?
airdrik
Registered Member
Posts
1854
Karma
5
OS
by "the desktop" I was referring to things generally associated with the desktop, which follow the freedesktop.org standards, which includes for example Konqueror and Dolphin, among other file managers, as well as application launcher widgets and shortcuts and things.
I'd be surprised if there were different behavior between Konqueror and Dolphin as Konqueror uses Dolphin's directory view for its directory view, though I think it may inject some file associations as it can open certain file types in-place instead of in a separate application.

The closest you'll be able to get for having .sql files behave the same way as .desktop files (without changing the code to add special handling) would be to set up the file association for .sql files so that the command used to run the .sql file is listed as the default application, then when you click on them it will "open" the .sql file using the command to execute them. Then to open the .sql file for editing, use the right-click menu and select the application from the Open With sub-menu. You can swap which command is used by default when clicking on the file by moving whichever application you want as the default to the top of the file associations list; the others will be listed in the Open With submenu.


airdrik, proud to be a member of KDE forums since 2008-Dec.
ba1po
Registered Member
Posts
5
Karma
0
OS
airdrik wrote:by "the desktop" I was referring to things generally associated with the desktop, which follow the freedesktop.org standards, which includes for example Konqueror and Dolphin, among other file managers, as well as application launcher widgets and shortcuts and things.
I'd be surprised if there were different behavior between Konqueror and Dolphin as Konqueror uses Dolphin's directory view for its directory view, though I think it may inject some file associations as it can open certain file types in-place instead of in a separate application.

The closest you'll be able to get for having .sql files behave the same way as .desktop files (without changing the code to add special handling) would be to set up the file association for .sql files so that the command used to run the .sql file is listed as the default application, then when you click on them it will "open" the .sql file using the command to execute them. Then to open the .sql file for editing, use the right-click menu and select the application from the Open With sub-menu. You can swap which command is used by default when clicking on the file by moving whichever application you want as the default to the top of the file associations list; the others will be listed in the Open With submenu.


Thanks again for your reply.
Indeed, setting up the association is a simple solution, but I'd like to create a more complex behaviour.
Would you happen to know where in Dolphin's code that behaviour is embedded?
I downloaded the source code for my distribution (debian), but found no files that handle that; I might have missed it.
Otherwise, it may be something not directly done by Dolphin, but by some kde/plasma daemon.
airdrik
Registered Member
Posts
1854
Karma
5
OS
I'm not familiar with the codebase, but I believe that would be defined in one of the KDE Framework Libraries relating to dolphin's folder view part.

Another option, if you just want to have a pop-up ask every time would be to write a script to use KDE's dialogs to ask and then either execute or open the file, and then set that as the default for that file type.


airdrik, proud to be a member of KDE forums since 2008-Dec.
ba1po
Registered Member
Posts
5
Karma
0
OS
airdrik wrote:I'm not familiar with the codebase, but I believe that would be defined in one of the KDE Framework Libraries relating to dolphin's folder view part.

Another option, if you just want to have a pop-up ask every time would be to write a script to use KDE's dialogs to ask and then either execute or open the file, and then set that as the default for that file type.


Thank you airdrik,

I will continue searching for the part of the code that manages that, as I would like to adapt it to my needs.

Best


Bookmarks



Who is online

Registered users: Bing [Bot], gfielding, Google [Bot], markhm, sethaaaa, Sogou [Bot], Yahoo [Bot]