• PCMANfm-Qt > Créer des actions personnalisées dans le menu contextuel

      Un très bon article mais en anglais sur PCManFm-Qt est dans le wiki de Manjaro :https://wiki.manjaro.org/index.php?title=PCmanFM-Qt

       

      Sous Debian il parait nécessaire d’installer le paquet dbus-x11

      CRÉER LE DOSSIER QUI RECEVRA LES FICHIERS .desktop

      mkdir -p ~/.local/share/file-manager/actions

      Fichier type

      [Desktop Entry]
      Type=Action
      Name=Ma super action
      Icon=dialog-password
      Profiles=A;
      
      [X-Action-Profile A]
      # mon action A
      Exec=gksu juffed %f

       

      gksu pour exécuter une commande avec sudo

       

      [Desktop Entry]
      Type=Action
      Name=Set As Wallpaper
      Icon=user-desktop
      Profiles=A;
      
      [X-Action-Profile A]
      MimeTypes=image/*;
      Exec=pcmanfm-qt -w %f
      SelectionCount==1

      “Compress” custom action

       

      [X-Action-Profile A]
      MimeTypes=all/all;
      Exec=apack %d/%n.tar.gz %F
      Name[en]=Default profile
      SelectionCount==1

      This will create a YOUR_USERNAME.tar.gz archive from the selected files/folders in the current directory.

      %d le dossier courant

      %n

      %F

       

      [X-Action-Profile A]
      MimeTypes=application/x-7z-compressed;application/x-7z-compressed-tar;application/x-ace;application/x-alz;application/x-ar;application/x-arj;application/x-bzip;application/x-bzip-compressed-tar;application/x-bzip1;application/x-bzip1-compressed-tar;application/x-cabinet;application/x-cbr;application/x-cbz;application/x-cd-image;application/x-compress;application/x-compressed-tar;application/x-cpio;application/x-deb;application/x-ear;application/x-ms-dos-executable;application/x-gtar;application/x-gzip;application/x-gzpostscript;application/x-java-archive;application/x-lha;application/x-lhz;application/x-lzip;application/x-lzip-compressed-tar;application/x-lzma;application/x-lzma-compressed-tar;application/x-lzop;application/x-lzop-compressed-tar;application/x-rar;application/x-rar-compressed;application/x-rpm;application/x-rzip;application/x-tar;application/x-tarz;application/x-stuffit;application/x-war;application/x-xz;application/x-xz-compressed-tar;application/x-zip;application/x-zip-compressed;application/x-zoo;application/zip;multipart/x-zip;
      Exec=atool --extract-to=%d %f
      Name[en]=Default profile
      SelectionCount==1

      This will uncompress the selected archive into the current directory.

      Custom Actions

      Chaque action peut être limitée à un type de fichier, ou à un certain endroit, visible donc uniquement avec ce type de fichier ou cet endroit.

      Chaque changement nécessite un redémarrage de PCmanFM-Qt

       

      A desktop entry has a name like "NAME.desktop" ("NAME" is sometimes called its "ID"). It starts with the [Desktop Entry] group, which can contain the following keys and their corresponding values:

       

      Type This can be Action or Menu. The latter creates a sub-menu with more actions. See Menu Definition.Menu Definition.

      Name The label of the action, as it appears in the context menu.Its localized variant can also be added, like Name[it]=….

      Icon The name of a theme icon.

      Description A free description of the action.Defaults to empty.

      Enabled A user might define many actions or menus, and choose to only enable some of them from time to time.Defaults to true.

      Profiles The ordered list of the profiles attached to this action, e.g. profile-zero;profile-one; See Profile Definition.Profile Definition.

       

      Chaque valeur peut être séparée par un ; pour un groupe de valeurs

      LES PROFILS

      Chaque profil dit ce qu’il faut faire et quand et est définition ainsi : [X-Action-Profile ID] où ID est le nom du profil.

       

      Exec commande à exécuter, avec ou non des arguments. Parameters are often used with this key.

      MimeTypes Liste des types de fichier avec lesquels le profil sera actif. La liste peut être singulière : audio/mpeg;, groupée: image/*;, ou négative: audio/*;!audio/mpeg;

      all/all: tout ● all/allfiles: que les fichiers ● inode/directory: que les dossiers

      Basenames Liste des noms de fichier/dossier acceptés. Joker * pour dire tous. Base names may be negated (*;!*.h;).Defaults to *;.

      Folders Liste des chemins acceptés pour faire apparaitre l’Action (/data;!/data/resources/secret;). Joker *, replacing any level(s) of subdirectory (e.g. /music;/video;!*/secret;).

      SelectionCount Spécifie le nombre d’éléments sélectionnés. (< ou = ou >} NOMBRE".  =1, >1, <10 (ne pas oublier le = avant !. SelectionCount==5

      Paramètres pour Exec

      List of parameters, used with Exec (the most common ones are %f, %F, %u and %U):

       

      Parameter Description Form

      %b (premier) basename singular

      %B space-separated list of basenames plural

      %c count of selected items irrelevant

      %d (premier) base directory singular

      %D space-separated list of base directory of each selected items plural

      %f (premier) file name singular

      %F liste des noms des fichiers séparés par un espace plural

      %h hostname of the (premier) URI irrelevant

      %m mimetype of the (premier) selected item singular

      %M space-separated list of the mimetypes of the selected items plural

      %n username of the (premeier) URI irrelevant

      %s scheme of the (premier) URI irrelevant

      %u (premier) URI singular

      %U space-separated list of selected URIs plural

      %w (premier) basename without the extension singular

      %W space-separated list of basenames without their extension plural

      %x (premier) extension singular

      %X space-separated list of extensions plural

      %% the "%" character irrelevant

      Exemples

      root-editor.desktop as:

      [Desktop Entry]
      Type=Action
      Icon=text-editor
      Name=In Root Text Editor
      Profiles=profile-zero;
      
      [X-Action-Profile profile-zero]
      SelectionCount==1
      MimeTypes=text/plain;
      Exec=lxsudo featherpad %f
      

      Now, if you right click a single text file ( does not appear when you right click a selection of multiple text files)

       

      set_wallpaper.desktop sets a right-clicked image as the wallpaper of LXQt desktop:

      [Desktop Entry]
      Type=Action
      Name=Set as wallpaper
      Icon=user-desktop
      Profiles=profile-zero;
      
      [X-Action-Profile profile-zero]
      SelectionCount==1
      MimeTypes=image/*;
      Exec=pcmanfm-qt -w %f
      

      To have a more flexible and complex custom action, you can make an executable Bash script and put its path plus an appropriate parameter as the value of Exec. In most systems, executables could also be called by their names if they are put inside the directory ~/bin. If that is not the case in your distro, you might want to add that directory to your PATH environment variable (consult your distro documentation).

      LES SOUS-MENUS

      A menu action defines a sub-menu with more actions. Its keys are like those of ordinary actions but, instead of Profiles, it has ItemsList:

       

      ItemsList The ordered list of the actions attached to this menu.Each element of this strings list is the ID of an action (its file name minus ".desktop"), e.g. root-editor;set_wallpaper;

       

      For example, if we have the two actions that were defined under the section Profile Definition, we could create ~/.local/share/file-manager/actions/misc-actions.desktop as:

      [Desktop Entry]
      Type=Menu
      Icon=unknown
      Name=Mes Actions
      ItemsList=root-editor;set_wallpaper;
      

      Then, if a text or image file is right clicked, a sub-menu item with the name "Miscellaneous Actions" will appear in its context menu and the relevant action will be in its sub-menu.

      The particular sub-menu created above is not useful in itself but shows how to group actions in sub-menus. For example, you can put all actions whose MimeTypes key is inode/directory; inside a "Folder Actions" sub-menu to have an uncluttered context menu.

      If the actions of a sub-menu are shown together (when their MimeTypes overlap), their order will be the same as in ItemsList.

      Ordre des Actions

      By default, top-level actions appear in alphabetical order (if they can appear together at all) but you can give them a different order by creating ~/.local/share/file-manager/actions/level-zero.directory as:

      [Desktop Entry]
      ItemsList=action1_id;action2_id;action3_id;...;
      

      ItemsList is as in Menu Definition but, here, it defines the order of top-level actions, as they appear in the context menu.

      ICÔNES

      Pour choisir un icone et (trouver son nom et voir à quoi il ressemble), faire un clic droit sur le menu Démarrer du tableau de bord > "Modifier les applications" > clic sur l’icone à gauche de "Exécuter le programme…" et choisir "Parcourir les icônes"

      MIME TYPES

      MimeTypes=MimeTypes=text/*;audio/*;image/*;application/*;video/*

       

      fichiers compressés

      MimeTypes=application/x-7z-compressed;application/x-7z-compressed-tar;application/x-ace;application/x-alz;application/x-ar;application/x-arj;application/x-bzip;application/x-bzip-compressed-tar;application/x-bzip1;application/x-bzip1-compressed-tar;application/x-cabinet;application/x-cbr;application/x-cbz;application/x-cd-image;application/x-compress;application/x-compressed-tar;application/x-cpio;application/x-deb;application/x-ear;application/x-ms-dos-executable;application/x-gtar;application/x-gzip;application/x-gzpostscript;application/x-java-archive;application/x-lha;application/x-lhz;application/x-lzip;application/x-lzip-compressed-tar;application/x-lzma;application/x-lzma-compressed-tar;application/x-lzop;application/x-lzop-compressed-tar;application/x-rar;application/x-rar-compressed;application/x-rpm;application/x-rzip;application/x-tar;application/x-tarz;application/x-stuffit;application/x-war;application/x-xz;application/x-xz-compressed-tar;application/x-zip;application/x-zip-compressed;application/x-zoo;application/zip;multipart/x-zip;

      EXEMPLES

      mount-iso

      [Desktop Entry]
      Type=Action
      Name=Monter le fichier iso
      Icon=application-x-cd-image
      Profiles=profile-zero;
      
      [X-Action-Profile profile-zero]
      MimeTypes=application/x-cd-image;application/x-raw-disk-image;
      #edit to path of fuseisomount script
      Exec=/chemin/vers/fuseisomount %w %f %d

      edit-tag-mp3

      [Desktop Entry]
      Type=Action
      Name=Modifier les balises mp3
      Icon=kid3-qt
      Profiles=profile-zero;
      
      [X-Action-Profile profile-zero]
      MimeTypes=audio/*;
      Exec=kid3-qt %F

      fuseisomount

      fuseiso -p $2 $3/iso_mount
      notify-send -a Isomount -i application-x-cd-image "$1.iso mounted in $3/iso_mount"

      backup_file

      [Desktop Entry]
      Type=Action
      Name=Backup file
      Icon=backup
      Profiles=profile-zero;
      
      [X-Action-Profile profile-zero]
      MimeTypes=MimeTypes=text/*;audio/*;image/*;application/*;video/*
      Exec=cp %f %f.~
      #With date and error message:
      #Exec=/path/to/localcopy %f

       

      #!/bin/bash
      /bin/cp "$1" "$1.$(date +%Y-%m-%d-%H%M).bak"
      res=$?
      if [[ $res != 0 ]] ; then
          zenity --error --text="Backup failed $1 (not root?)"
      fi

       

       

       

 

Aucun commentaire

 

Laissez un commentaire