| Both sides previous revision Previous revision | |
| scripting_pcmanfm [2025/10/28 19:34] – [Scripting Example] crcerror | scripting_pcmanfm [2025/10/29 20:35] (current) – Some juggling with text crcerror |
|---|
| * ''/usr/share/applications/defaults.list'' | * ''/usr/share/applications/defaults.list'' |
| |
| The corrospending user-space space for actions, desktop applets and default MIME are stored in: | The corrospending user-space for actions, desktop applets and default MIME are stored in: |
| * ''/userdata/system/.local/share/file-manager/actions/'' | * ''/userdata/system/.local/share/file-manager/actions/'' |
| * ''/userdata/system/.local/share/applications'' | * ''/userdata/system/.local/share/applications'' |
| ===== MIME types ===== | ===== MIME types ===== |
| |
| Unlike Windows systems, it is much less common in Linux to identify files by their ‘file extensions’. Instead, the operating system recognises the file type based on file permissions and metadata, not just the extension. However, common file extensions are still used for organisation and compatibility, for example for compressed archives such as .gz and .bz2 or Office formats such as .odt and .docx or for some special usage like ''make'' | Unlike Windows systems, it is much less common in Linux to identify files by the ‘file extensions’. Instead, the operating system recognises the file type based on file permissions and metadata, not just the extension. However, common file extensions are still used for organisation and compatibility, for example for compressed archives such as .gz and .bz2 or Office formats such as .odt and .docx or for some special usage like ''make'' |
| |
| So yes, we are talking about MIME (aka Multipurpose Internet Mail Extensions) types, rather then file extenions. Best praxis to determine the MIME-type that PCManFM uses is, if you just right-click the file and then read it's properties. Or you can just select the file and you'll the file-description into the down-left corner of the filemanager. Valid descriptions are ''plain/text'' or ''inode/directory'' (for directories) or ''application/zip'' - you've got the idea. | So yes, we are talking about MIME (aka Multipurpose Internet Mail Extensions) types, rather then file extenions. Best praxis to determine the MIME-type that PCManFM uses is, if you just right-click the file and then read its properties. Or you can just select the file and you'll the file-description into the down-left corner of the filemanager. Valid descriptions are ''plain/text'' or ''inode/directory'' (for directories) or ''application/zip'' - you've got the idea. |
| |
| ===== Link a MIME type to an application (manual) ===== | ===== Link a MIME type to an application (manual) ===== |
| |
| You doubleclick on a file that is not yet bound to an application then a small window appears, asking which application should be used in future to open. You click on ''Custom Command Line'' and from there type the command or browse through your filesystem. | Doubleclick on a file that is not yet bound to an application, then a small window appears that's asking which application should be used open the file. You click on ''Custom Command Line'' register and from there you can type the command or browse your filesystem to select a valid file-application. |
| |
| **Important steps:** | **Important steps:** |
| - Fill in Application name (name it as you like) | - Fill: Application name (free selectable, as you like) |
| - tick: Set selected application as default for this file type | - Tick: Set selected application as default for this file type |
| |
| So the needed data was set to: ''/userdata/system/.config/mimeapps.list'', if you edit this file you will see an entry like | All data is set to: ''/userdata/system/.config/mimeapps.list'', if you edit this file you will see an entry like |
| |
| <code> | <code> |
| </code> | </code> |
| |
| So you see: I associated MIME **font/ttf** and used **l3afpad** as application. | So you see: Associated MIME is **font/ttf** and used application is **l3afpad**. |
| |
| The **.desktop**-file contains all the additional data and can be found in ''/userdata/system/.local/share/applications'' from here you can change some values or set your own script in the **EXE**-Section and see even the **Name** you gave it. **Type=Application** is important here, this will indicate PCManFM that this file is an application type. | The **.desktop**-file contains all the additional data and can be found in ''/userdata/system/.local/share/applications'' from here you can change some values or set your own script in the **EXE**-Section and see even the **Name** you gave it. **Type=Application** is important here, this will indicate PCManFM that this file is an application type. |
| * ''all/allfiles'': matches only files | * ''all/allfiles'': matches only files |
| * ''inode/directory'': matches only directories | * ''inode/directory'': matches only directories |
| |
| |
| |
| ==== PCManFM creating an entry in Contextmenu and using Cascaded Contextmenus ==== | ==== PCManFM creating an entry in Contextmenu and using Cascaded Contextmenus ==== |
| If you place your **.desktop** files to ''/userdata/system/.local/share/file-manager/actions/'' you can create entries in context menus by right clicking on a file or folder. I've created a small application that calculates the md5sum of all selected files. Talking about the Type you see here the **Type=Action** is present. You'll also need the profile settings. | If you place your **.desktop** files to ''/userdata/system/.local/share/file-manager/actions/'' you can create entries in context menus by right clicking on a file or folder. I've created a small application that calculates the md5sum of all selected files. Talking about the Type you see here the **Type=Action** is present. You'll also need the profile settings. |
| |
| <code> | <code bash| system.md5sum.desktop> |
| [Desktop Entry] | [Desktop Entry] |
| Type=Action | Type=Action |
| === Creating a Cascaded Contextmenu === | === Creating a Cascaded Contextmenu === |
| |
| Again, just change the Type you want to descripe into the **.desktop** file and use **Type=Menu** - rather undocumented it seems not to work to set the Name only instead use **Tooltip** to get the name readable. Then arrange just types of **.desktop**-files you want into your **ItemList** (remember, only the one placed in the DIR ''action'' will work) and just dismiss the desktop-extension. | Again, just change the **Type** you want to descripe into the **.desktop** file and use **Type=Menu** - rather undocumented it seems not to work to set the Name only instead use **Tooltip** to get the entry visible into the context menu. Then just enter the **.desktop**-files you want into your **ItemList** (remember, only the one placed in the DIR ''action'' will work) and just dismiss the desktop-extension. |
| |
| <code> | <code bash| menu.cascade-example.desktop> |
| [Desktop Entry] | [Desktop Entry] |
| Type=Menu | Type=Menu |
| Here you see how PCManFMs internal parametes are used. ''%d'' is the path (dirname) of the first file, so change directory to this. Later ''%B'' is used to work with the filenames only to deal with the for-loop and to operate the filenames. The big challange is to mask all quotes. Selection Count is set to hinder unintended renaming (for example you marked 1000 of rom files and hit the context entry for example). | Here you see how PCManFMs internal parametes are used. ''%d'' is the path (dirname) of the first file, so change directory to this. Later ''%B'' is used to work with the filenames only to deal with the for-loop and to operate the filenames. The big challange is to mask all quotes. Selection Count is set to hinder unintended renaming (for example you marked 1000 of rom files and hit the context entry for example). |
| |
| <code> | **Destination:** ''/userdata/system/.local/share/file-manager/actions/'' |
| | |
| | <code bash| system.toggle-filenames.desktop> |
| [Desktop Entry] | [Desktop Entry] |
| Type=Action | Type=Action |
| === Create WINE autorun.cmd === | === Create WINE autorun.cmd === |
| |
| You enter the gamefolder and click on a windows-exe-file. From there select ''Create autorun.cmd'' (Attention, no backup of your old ''autorun.cmd'' will be made). I made this because here you see that you heavily have to look out which variables you are using. If you need a literal ''%'' you have to write it twice - escape all quotes and use ''printf'' rather then ''echo'' | You enter the gamefolder and click on a windows-exe-file. From there select ''Create autorun.cmd'' (Attention, no backup of your old ''autorun.cmd'' will be made). I made this because here you see that you heavily have to look out which variables you are using. If you need a literal ''%'' you have to write it twice - escape all quotes and use ''printf'' rather then ''echo''. This script will work only if you are within ''/userdata/roms/windows''. |
| |
| * p1 = Location of all wine-games | * p1 = Location of all wine-games |
| * p3 = Windows game directoy itself | * p3 = Windows game directoy itself |
| |
| So with clever subtrating the strings you can extract all data you need and you can savely write back the needed info | So with clever subtrating the strings you can extract all data you need and you are able to write back the needed data to ''autorun.cmd'' |
| |
| <code> | **Destination:** ''/userdata/system/.local/share/file-manager/actions/'' |
| | |
| | <code bash| wine.create-autorun.desktop> |
| [Desktop Entry] | [Desktop Entry] |
| Type=Action | Type=Action |
| Name=Create autorun.cmd | Name=Create autorun.cmd |
| | Folders=/userdata/roms/windows/*; |
| Profiles=Batocera | Profiles=Batocera |
| | SelectionCount==1 |
| |
| [X-Action-Profile Batocera] | [X-Action-Profile Batocera] |
| MimeTypes=application/x-ms-dos-executable | MimeTypes=application/x-ms-dos-executable |
| Exec=bash -c "p1=/userdata/roms/windows/; p2=%d; p3=${p2/$p1/}; p3=${p3%%\/*}; printf 'CMD=\"%%s\"\nDIR=%%s' %b \"${p2/$p1$p3/.}\" > \"$p1$p3/autorun.cmd\";" | Exec=bash -c "p1=/userdata/roms/windows/; p2=%d; p3=${p2/$p1/}; p3=${p3%%%%\/*}; printf 'CMD=\"%%s\"\nDIR=%%s' %b \"${p2/$p1$p3/.}\" > \"$p1$p3/autorun.cmd\";" |
| </code> | </code> |