Ubuntu 22.04LTSで廃止された Nautilus ファイルマネージャ向け拡張ツール、Filemanager Actions の仕様を引き継ぎつつも一から作り直された Actions For Nautilus をインストールし、以前作ったカスタムアクションを全て移植しました。
Ubuntu22.04で消えたFilemanager Actions
UbuntuのファイルマネージャNautilusの右クリックで出て来るメニューに、様々な機能を追加することが出来るFilemanager Actionについては、以前記事にした通り日々愛用してきました。
Ubuntu 22.04へアップグレード後、機能検証を進めている中で、右クリックメニューに割り当てていたこうしたカスタムアクションが無くなっていることに気づき、調べてみると残念な事実を知ることとなりました。
ただ、上記スレッドの回答の中に、Filemanager Actionの仕様を引き継ぎつつも、一から開発されたActions For Nautilusと言う代替ツールの存在を知りました。
代替ツール Actions For Nautilusを導入
Actions For Nautilusの公式GitHubには、導入から仕様、使い方から使用例まで、全て丁寧にドキュメント化されています。
今回導入してみる環境は、Ubuntu 22.04 LTS です。
1 2 3 4 5 6 7 8 9 10 |
$ uname -a Linux BionicUSB 5.15.0-53-generic #59-Ubuntu SMP Mon Oct 17 18:53:30 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy $ nautilus --version GNOME nautilus 42.2 |
Actions For Nautilusをインストールする前に、必要な依存パッケージをaptパッケージマネージャでインストールしておきます。
1 2 3 4 |
$ sudo apt install python3-gi procps libjs-jquery libjs-jquery はすでに最新バージョン (3.6.0+dfsg+~3.5.13-1) です。 procps はすでに最新バージョン (2:3.3.17-6ubuntu2) です。 python3-gi はすでに最新バージョン (3.42.1-0ubuntu1) です。 |
GitHubで公開されているdebファイルをダウンロードの上、インストールします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
$ wget https://github.com/bassmanitram/actions-for-nautilus/raw/main/dist/actions-for-nautilus_1.5.1_all.deb --2022-11-30 20:46:30-- https://github.com/bassmanitram/actions-for-nautilus/raw/main/dist/actions-for-nautilus_1.5.1_all.deb github.com (github.com) をDNSに問いあわせています... 20.205.243.166 github.com (github.com)|20.205.243.166|:443 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... 302 Found 場所: https://raw.githubusercontent.com/bassmanitram/actions-for-nautilus/main/dist/actions-for-nautilus_1.5.1_all.deb [続く] --2022-11-30 20:46:31-- https://raw.githubusercontent.com/bassmanitram/actions-for-nautilus/main/dist/actions-for-nautilus_1.5.1_all.deb raw.githubusercontent.com (raw.githubusercontent.com) をDNSに問いあわせています... 185.199.110.133, 185.199.109.133, 185.199.108.133, ... raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... 200 OK 長さ: 983342 (960K) [application/octet-stream] ‘actions-for-nautilus_1.5.1_all.deb’ に保存中 actions-for-nautilus_1.5.1_all.deb 100%[====================================>] 960.29K --.-KB/s in 0.07s 2022-11-30 20:46:32 (14.0 MB/s) - ‘actions-for-nautilus_1.5.1_all.deb’ へ保存完了 [983342/983342] $ dpkg --info actions-for-nautilus_1.5.1_all.deb new Debian package, version 2.0. size 983342 bytes: control archive=696 bytes. 1099 バイト、 20 行 control Package: actions-for-nautilus Version: 1.5.1 Maintainer: Martin Bartlett <martin.j.bartlett@gmail.com> Architecture: all Description: Nautilus extension for creating selection context menu entries Actions For Nautilus is an extension to the Gnome Nautilus file manager that allows you to create context menu action items that execute arbitrary commands when activated. The action items can be organized into submenus, and they can be configured to appear only when the files in the selection match file type and/or mimetype and/or path pattern rules, as well as based upon the number of files in the selection. This is intended to be a replacement for the Nautilus functionality of the now-discontinued Filemanager Actions extension and supports most of the features and semantics of that extension. Depends: python3 (>= 3.10.0), python3-nautilus (>= 1.2.3), procps (>= 2:3), libjs-jquery (>= 3.5.0), xdg-utils (>= 1.1.0) Suggests: zenity (>= 3.0.0), xclip (>= 0.10-0), bash (>= 4.0) Section: gnome Priority: optional Homepage: https://github.com/bassmanitram/actions-for-nautilus $ sudo dpkg -i actions-for-nautilus_1.5.1_all.deb actions-for-nautilus_1.5.1_all.deb を展開する準備をしています ... actions-for-nautilus (1.5.1) で (1.5.1 に) 上書き展開しています ... actions-for-nautilus (1.5.1) を設定しています ... gnome-menus (3.36.0-1ubuntu3) のトリガを処理しています ... desktop-file-utils (0.26-1ubuntu3) のトリガを処理しています ... bamfdaemon (0.5.6+22.04.20220217-0ubuntu1) のトリガを処理しています ... Rebuilding /usr/share/applications/bamf-2.index... mailcap (3.70+nmu1ubuntu1) のトリガを処理しています ... |
設定UIと使用感
アプリケーションの一覧で検索すると見つかるアイコンをクリックして設定UIを開きます。
するとブラウザが開いてびっくりするのですが、ブラウザベース( localhost:55913 )の設定UIなのだそうです。
インストール時にいくつかサンプルアクションが入っていて、それらをフォーム形式で設定できる他、生のJSONファイルを直接編集するビューも用意されています。
1 |
~/.local/share/actions-for-nautilus/config.json |
メニューはサブメニューで入れ子状にすることも可能。
アクションを設定したら、Nautilusを再起動して反映させます。
1 2 3 |
$ nautilus -q $ nautilus --no-desktop (org.gnome.Nautilus:80459): Gtk-WARNING **: 10:20:39.879: cannot open display: |
Nautilus上でファイルを右クリックしてみると、Filemanager Actionの時と異なり階層の一番上に列記されるので、このままではメニューが縦長になりすぎないか心配。
そこで、これから追加するカスタムアクションは、全て More Actions... というサブメニューを作って格納することにします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
{ "actions": [ { "type": "menu", "label": "More Actions...", "actions": [ {}, {}, {}, {} ] } ], "debug": false } |
サンプルアクションの1つ、 Test All Place Holders は、Actions for Nautilusで利用できる全引数の参照結果を表示してくれるもので、これには zenity というパッケージが必要です。
またクリップボードへファイル名やフルパスをコピーする Copy details 内のアクションは、 xclip パッケージが無いと機能しません。
それではここから、過去に作ったFilemanager Actionのカスタムアクションを、Actions for Nautilusへ移植していきます。
1.画像やPDFのメタデータ消去
PDFや画像を誰かに送る際に気になるメタデータをクリック一発で削除してくれるこのアクションは、 exiftool が別途必要です。
Filemanager Actionでの設定をまとめると以下の通り。
- Label : Remove Exif
- Command : exiftool -P -all= %f
- Exec Mode : In a Terminal
- Working Dir: %d
- Basenames : *.png OR *.pdf OR *.jpg (Unmatch Case)
Actions for Nautilusでは、MIMEタイプを活用して次のようなアクションを組みました。
1 2 3 4 5 6 7 8 9 |
, { "type": "command", "label": "Remove Exif", "command_line": "exiftool -P -all= %f", "use_shell": true, "cwd": "%d", "filetypes": ["file"], "mimetypes": ["image/*", "application/pdf"] } |
なお、 filetypes , mimetypes 各項の値は、複数でなくとも必ず鉤括弧 ["...."] で囲まないと、正しく認識してくれないようです。
実行するとメタデータの削除後、オリジナルファイルも _original という名前で複製されて残ります。
2.PDFをページ毎のPNG画像へ変換
複数ページのPDFを単ページのPNG画像へ変換出力してくれるこのアクションは、ImageMagickが必要で、さらに -alpha オプションを使うので、ポリシーファイルの改変が必要です。
1 2 3 4 5 6 7 |
BEFORE) <!-- disable ghostscript format types --> <policy domain="coder" rights="none" pattern="PDF" /> AFTER) <!-- disable ghostscript format types --> <policy domain="coder" rights="read|write" pattern="PDF" /> |
Filemanager Actionでの設定は以下の通り。
- Label : PDF->PNG
- Command : convert -density 300 -alpha off %f %w.png
- Exec Mode : In a Terminal
- Working Dir: %d
- Basenames : *.pdf
これがActions for Nautilusでは次のようになります。
1 2 3 4 5 6 7 8 9 |
, { "type": "command", "label": "PDF->PNG", "command_line": "convert -density 300 -alpha off %f %w.png", "use_shell": true, "cwd": "%d", "filetypes": ["file"], "mimetypes": ["application/pdf"] } |
実行するとPDFファイル名に連番が付与された、各ページのPNG画像が生成されます。
3.複数画像の結合(縦方向・横方向)
2枚の画像を縦方向・横方向に結合するこのアクションも、ImageMagickにより実現しています。
縦方向・横方向それぞれ、Filemanager Actionではこのような設定でした。
- Label : Append Image Horiz #横方向
- Label : Append Image Vert #縦方向
- Command : convert +append %F %d/%w.append.%x #横方向
- Command : convert -append %F %d/%w.append.%x #縦方向
- Exec Mode : In a Terminal
- Working Dir: %d
- Basenames : *.png *.jpg *.gif
- Environment: more than 1
Actions for Nautilusでは、 min_items で最小選択数を設定することで、複数選択時にしか表示されないようにしています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
, { "type": "command", "label": "Append Image Horiz", "command_line": "convert +append %F %d/%w.append.%x", "use_shell": true, "cwd": "%d", "filetypes": ["file"], "mimetypes": ["image/*"], "min_items": 2 } , { "type": "command", "label": "Append Image Vert", "command_line": "convert -append %F %d/%w.append.%x", "use_shell": true, "cwd": "%d", "filetypes": ["file"], "mimetypes": ["image/*"], "min_items": 2 } |
実行すると結合されたファイルは、 .append と言うファイル名が付与されて生成されます。
4.ディレクトリ・ファイル一覧のツリー表示
treeコマンドの実行結果をテキストファイルに出力するアクションです。
- Label : Gen Tree File
- Command : tree %w -o %d/tree.txt
- Exec Mode : In a Terminal
- Working Dir: %d
- Mimetypes : inode/directory
Actions for Nautilusでは、作例にあった zenity コマンドへ渡す仕様に変えてみました。
1 2 3 4 5 6 7 8 9 10 |
, { "type": "command", "label": "Tree Dir", "command_line": "tree %w | zenity --title \"Directory Tree\" --text-info", "use_shell": true, "cwd": "%d", "filetypes": ["directory"], "mimetypes": ["inode/directory"], "max_items": 1 } |
実行結果は、 zenity の生成したウィンドウで選択コピー可能です。
5.pdftkによるPDFファイルの結合と一括回転操作
このアクションで使うPDFtkは、 snap で予めインストールしておきます。
1 2 3 4 5 6 7 |
$ pdftk コマンド 'pdftk' が見つかりません。次の方法でインストールできます: sudo snap install pdftk # version 2.02-4, or sudo apt install pdftk-java # version 3.2.2-1 他のバージョンについては 'snap info pdftk' を確認してください。 $ sudo snap install pdftk pdftk 2.02-4 from Scott Moser (smoser) installed |
複数PDFファイルを結合するアクションはこのような設定にしていました。
- Label : Merge PDF
- Command : pdftk %F cat output %d/%w.merge.%x
- Exec Mode : In a Terminal
- Working Dir: %d
- Basenames : *.pdf
- Environment: more than 1
これが、Actions for Nautilusでは次のようになります。
1 2 3 4 5 6 7 8 9 10 |
, { "type": "command", "label": "Merge PDF", "command_line": "pdftk %F cat output %d/%w.merge.%x", "use_shell": true, "cwd": "%d", "filetypes": ["file", "!directory"], "mimetypes": ["application/pdf"], "min_items": 2 } |
続いてPDF内の全ページを180度回転させるアクションは、以下の要領だったのが、
- Label : Rotate180 PDF
- Command : pdftk %f cat 1-enddown output %W.rotate.%x
- Exec Mode : In a Terminal
- Working Dir: %d
- Basenames : *.pdf
Actions for Nautilusでは次のようになります。
1 2 3 4 5 6 7 8 9 |
, { "type": "command", "label": "Rotate180 PDF", "command_line": "pdftk %f cat 1-enddown output %W.rotate.%x", "use_shell": true, "cwd": "%d", "filetypes": ["file", "!directory"], "mimetypes": ["application/pdf"] } |
実行すると、結合時は.merge、回転時は.rotateという名前でファイルが生成されます。
以上、設定ファイル全体は、以下のようになりました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
{ "actions": [ { "type": "menu", "label": "More Actions...", "actions": [ { "type": "command", "label": "Remove Exif", "command_line": "exiftool -P -all= %f", "use_shell": true, "cwd": "%d", "filetypes": ["file"], "mimetypes": ["image/*", "application/pdf"] } , { "type": "command", "label": "PDF->PNG", "command_line": "convert -density 300 -alpha off %f %w.png", "use_shell": true, "cwd": "%d", "filetypes": ["file"], "mimetypes": ["application/pdf"] } , { "type": "command", "label": "Append Image Horiz", "command_line": "convert +append %F %d/%w.append.%x", "use_shell": true, "cwd": "%d", "filetypes": ["file"], "mimetypes": ["image/*"], "min_items": 2 } , { "type": "command", "label": "Append Image Vert", "command_line": "convert -append %F %d/%w.append.%x", "use_shell": true, "cwd": "%d", "filetypes": ["file"], "mimetypes": ["image/*"], "min_items": 2 } , { "type": "command", "label": "Tree Dir", "command_line": "tree %w | zenity --title \"Directory Tree\" --text-info", "use_shell": true, "cwd": "%d", "filetypes": ["directory"], "mimetypes": ["inode/directory"], "max_items": 1 } , { "type": "command", "label": "Merge PDF", "command_line": "pdftk %F cat output %d/%w.merge.%x", "use_shell": true, "cwd": "%d", "filetypes": ["file", "!directory"], "mimetypes": ["application/pdf"], "min_items": 2 } , { "type": "command", "label": "Rotate180 PDF", "command_line": "pdftk %f cat 1-enddown output %W.rotate.%x", "use_shell": true, "cwd": "%d", "filetypes": ["file", "!directory"], "mimetypes": ["application/pdf"] } , { "type": "command", "label": "Test all place holders", "command_line": "%O printf '%%s\\n' '#b' %b '#B' %B '#c' %c '#d' %d '#D' %D '#f' %f '#F' %F '#h' %h '#m' %m '#M' %M '#n' %n '#o' %o '#O' %O '#p' %p '#s' %s '#u' %u '#U' %U '#w' %w '#W' %W '#x' %x '#X' %X | zenity --title \"Test all place holders\" --text-info", "use_shell": true } , { "type": "command", "label": "Open in gedit", "command_line": "gedit %F", "filetypes": ["!directory", "standard"] } , { "type": "command", "label": "Copy path", "command_line": "echo -n %F | xclip -f -selection primary | xclip -selection clipboard", "use_shell": true } ] } ], "debug": false } |