|
| 1 | +# Open a JSON file with Tuw |
| 2 | + |
| 3 | +Tuw can take the first argument as a JSON path if the path includes a file extension. By renaming your JSON files to `*.tuw` and setting Tuw as a default application for `*.tuw` files, you can launch GUIs just by clicking on the files. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +On Windows, setting Tuw as the default application is straightforward. However, for other operating systems, the process is a bit more complex. Below are examples of how to set it up on Ubuntu 20.04 and macOS 10.15. |
| 8 | + |
| 9 | +## Ubuntu 20.04 |
| 10 | + |
| 11 | +### 1. Add `application/x-tuw` to `~/.local/share/mime/packages/Overrides.xml` |
| 12 | + |
| 13 | +(Make `Overrides.xml` if it does not exist.) |
| 14 | + |
| 15 | +```xml |
| 16 | +<?xml version="1.0" encoding="UTF-8"?> |
| 17 | +<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> |
| 18 | + <mime-type type="application/x-tuw"> |
| 19 | + <comment>TUW custom file</comment> |
| 20 | + <glob pattern="*.tuw"/> |
| 21 | + </mime-type> |
| 22 | +</mime-info> |
| 23 | +``` |
| 24 | + |
| 25 | +### 2. Make `~/.local/share/applications/tuw.desktop` |
| 26 | + |
| 27 | +Replace `/full/path/to/Tuw` with your path to Tuw. And save it as `tuw.desktop`. |
| 28 | + |
| 29 | +```ini |
| 30 | +[Desktop Entry] |
| 31 | +Version=1.0 |
| 32 | +Type=Application |
| 33 | +Name=Tuw |
| 34 | +Comment=Tiny GUI wrapper for CLI tools |
| 35 | +Exec=/full/path/to/Tuw %f |
| 36 | +Terminal=false |
| 37 | +MimeType=application/x-tuw; |
| 38 | +Categories=Utility;Application; |
| 39 | +``` |
| 40 | + |
| 41 | +### 3. Update database |
| 42 | + |
| 43 | +You can apply the changes with the following commands. |
| 44 | + |
| 45 | +```console |
| 46 | +update-mime-database ~/.local/share/mime |
| 47 | +update-desktop-database ~/.local/share/applications/ |
| 48 | +xdg-mime default tuw.desktop application/x-tuw |
| 49 | +``` |
| 50 | + |
| 51 | +## macOS 10.15 |
| 52 | + |
| 53 | +### 1. Make a wrapper with AppleScript |
| 54 | + |
| 55 | +Open the script editor and write the following AppleScript. And replace `/full/path/to/Tuw` with your path to Tuw. |
| 56 | + |
| 57 | +```scpt |
| 58 | +on open fileList |
| 59 | + -- Modify this variable for your environment |
| 60 | + set exePath to "/full/path/to/Tuw" |
| 61 | +
|
| 62 | + set filePath to item 1 of fileList |
| 63 | + set posixFilePath to POSIX path of filePath |
| 64 | +
|
| 65 | + tell application "Terminal" |
| 66 | + do script exePath & " " & posixFilePath & "; exit;" |
| 67 | + end tell |
| 68 | +end open |
| 69 | +``` |
| 70 | + |
| 71 | +### 2. Export the script as an application (File > Export...) |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +### 3. Right click a .tuw file and set Tuw as a default application |
0 commit comments