Z Zeleznick

Z Zeleznick

<details> <summary> <code>lib/image-grid.js</code> </summary>
// lib/image-grid.js
const DEFAULT_LIMIT = 10000; // 1000; // 100;
const DEBUG = { ENABLED: false };
const debug = (...args) => DEBUG.ENABLED && console.log(...args)
const info = (...args) => console.log(...args)
export const enableDebugMode = () => { DEBUG.ENABLED = true }
const getImages = (filepath, maxdepth) => {
// NOTE: options to use "-ctime -90d" / "-atime -90d" to filter more results
const findCommand = `find -E ${filepath} -iregex '.*\.(jpg|jpeg|png|gif)' -maxdepth ${maxdepth}`
const findSortedCommand = `${findCommand} -print0 | xargs -0 ls -at`
debug("findSortedCommand", findSortedCommand)
return exec(findSortedCommand, { silent: true }).toString().split("\n").filter(v => v)
}
const buildImageModal = (payload) => {
let {file} = payload;
const img = `<img src="${file}">`
return `<div class="imgContainer">${img}</div>`
}
const injectCss = (html) => {
// our tailwind build doesn't include grid css
// we add some custom styles as well
const css = `
/* Mimic tailwind grid css */
.grid {display:grid}
.grid-cols-3 {grid-template-columns: repeat(3, minmax(0, 1fr))}
.grid-cols-4 {grid-template-columns: repeat(4, minmax(0, 1fr))}
.grid-cols-5 {grid-template-columns: repeat(5, minmax(0, 1fr))}
/* custom css to center images in grid */
.grid div {place-items: center; padding: clamp(1px, 4%, 25px);}
.imgContainer {display: flex;}
`
const style = `<style type="text/css">${css}</style>`
return `${style}${html}`
}
const buildPage = (imageObjects, limit = DEFAULT_LIMIT) => {
const subset = imageObjects
.slice(0, limit)
.map(file => { return { file } })
const columns = subset.length > 32 ? (subset.length > 64 ? 5 : 4) : 3
const modals = subset.map(buildImageModal).join('\n')
const html = `<div class="grid grid-cols-${columns} pt-1 m-1">${modals}</div>`
const page = injectCss(html)
debug(page);
info('buildPage: Done')
return page
}
export const buildImagesPanel = async (filepath, maxdepth, limit) => {
const images = getImages(filepath, maxdepth);
info(`Found ${images.length} images`);
await arg({
input: " ",
}, buildPage(images, limit));
}
</details> <details> <summary> <code>view-desktop.js</code> </summary>
// Menu: View Desktop
// Description: View Desktop Attachments
// Author: Zach Zeleznick
// Twitter: @zzxiv
// Shortcut: cmd shift d
const {buildImagesPanel} = await lib("image-grid")
const filepath = "~/Desktop"
const depth = "3"
await buildImagesPanel(filepath, depth)
</details> <details> <summary> <code>view-attachments.js</code> </summary>
// Menu: View Attachment
// Description: View iMessage Attachments
// Author: Zach Zeleznick
// Twitter: @zzxiv
// Shortcut: cmd shift l
const {buildImagesPanel} = await lib("image-grid")
// NOTE: Need to grant Kit app full disk access in Security and Privacy or find will return 0 results
const filepath = "~/Library/Messages/Attachments"
const depth = "4"
await buildImagesPanel(filepath, depth)
</details> <details> <summary> <code>view-downloads.js</code> </summary>
// Menu: View Download
// Description: View Download Attachments
// Author: Zach Zeleznick
// Twitter: @zzxiv
// Shortcut: cmd shift 0
const {buildImagesPanel, enableDebugMode} = await lib("image-grid")
const filepath = "~/Downloads"
const depth = "2"
const limit = 42
enableDebugMode()
await buildImagesPanel(filepath, depth, limit)
</details> <table> <tr> <td><img width="863" alt="Native View" src="https://user-images.githubusercontent.com/5779832/116947788-7a972480-ac32-11eb-9e22-10dfb1fa3dff.png"></td> <td><img width="490" alt="Sorting Options" src="https://user-images.githubusercontent.com/5779832/116947778-779c3400-ac32-11eb-9378-4bb8c97012d6.png"></td> </tr> <tr> <td>Example search for `png` files on my Desktop</td> <td>Sorting options</td> </tr> </table>