Created Developer Tools (markdown)
44
Developer-Tools.md
Normal file
44
Developer-Tools.md
Normal file
@@ -0,0 +1,44 @@
|
||||
For those of you interested in extending osxphotos, using osxphotos to build your own tools, or just wanting to dig deeper into the Photos database, I've added some simple but useful tools I've been using to help develop osxphotos to the osxphotos CLI. The following commands are things I found useful as I work on adding new features or debugging osxphotos:
|
||||
|
||||
- `osxphotos repl`
|
||||
- `osxphotos uuid`
|
||||
- `osxphotos snap`
|
||||
- `osxphotos diff`
|
||||
- `osxphotos install`
|
||||
- `osxphotos uninstall`
|
||||
|
||||
|
||||
## repl
|
||||
|
||||
The repl (read-eval-print loop) command has been part of osxphotos since v0.42.41. It loads the Photos database then opens an interactive python REPL that allows you to easily explore the underlying data or quickly prototype code. The osxphotos repl uses [ptpython](https://github.com/prompt-toolkit/ptpython) to provide an interactive experience and includes [objexplorer](https://github.com/kylepollina/objexplore) to allow you to interactively explore the osxphotos data structures.
|
||||
|
||||
Try launching the repl with a photo selected in Photos then try `explore(selected[0])`
|
||||
|
||||
<img width="1008" alt="Screen Shot 2022-01-14 at 4 01 07 PM" src="https://user-images.githubusercontent.com/41546558/149599853-87498845-6ea5-4081-9212-8e49d96e32e3.png">
|
||||
|
||||
|
||||
## uuid
|
||||
|
||||
This is a simple command that simply prints out the unique ID (UUID) which Photos uses to identify each asset in the library. To use this command, select one or more photos in Photos then type `osxphotos uuid`. You can use the -f flag to also print out the filename in a format usable by the `--uuid-from-file` and `--skip-uuid-from-file` options.
|
||||
|
||||
```
|
||||
$ osxphotos uuid
|
||||
7783E8E6-9CAC-40F3-BE22-81FB7051C266
|
||||
$ osxphotos uuid -f
|
||||
# IMG_3092.heic
|
||||
7783E8E6-9CAC-40F3-BE22-81FB7051C266
|
||||
```
|
||||
|
||||
## snap, diff
|
||||
|
||||
`osxphotos snap` creates a snapshot copy of the Photos database. It copies only the database files, not the entire library. When combined with `osxphotos diff`, which does a diff of the current database to the most recent snapshot, this is a very useful tool for understanding how Photos stores data in the library. For example:
|
||||
|
||||
<img width="721" alt="Screen Shot 2022-01-14 at 3 56 54 PM" src="https://user-images.githubusercontent.com/41546558/149599618-6b375813-a5ba-4bac-a172-0675f3fcff89.png">
|
||||
|
||||
Make a change (rename a photo), then:
|
||||
|
||||
<img width="1011" alt="Screen Shot 2022-01-14 at 3 58 06 PM" src="https://user-images.githubusercontent.com/41546558/149599687-0fa263a5-dae1-41cf-be27-f2046d18c1e4.png">
|
||||
|
||||
# install / uninstall
|
||||
|
||||
The final two commands install or uninstall python packages into the same virtual environment that osxphotos is running in. These are primarily used for developing plugins when you've installed osxphotos via [pipx](https://github.com/pypa/pipx) which is the recommended approach. pipx handles creating a virtual environment for you but if you are developing a custom plugin function to use with the `--query-function`, `--post-function` or `{function}` template, and you need to install an external dependency, you'll need to inject those dependencies into the virtual environment set up by pipx. You can use `pipx inject` for this but many people don't know about that feature so I added the ability for osxphotos to do this itself.
|
||||
Reference in New Issue
Block a user