-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.ts
More file actions
55 lines (50 loc) · 1.81 KB
/
Copy pathbasic.ts
File metadata and controls
55 lines (50 loc) · 1.81 KB
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
/* eslint-disable no-console */
import { mdfind, type MdfindError } from 'mdfind-node'
async function main() {
try {
// Basic search for all PDF files
console.log('\n1. Finding PDF files in Downloads:')
const pdfFiles = await mdfind('kMDItemContentType == "com.adobe.pdf"', {
onlyIn: '~/Downloads'
})
console.log(`Found ${pdfFiles.length} PDF files`)
console.log('First 3:', pdfFiles.slice(0, 3))
// Search for images in Downloads folder
console.log('\n2. Finding PNG images in Downloads:')
const imageFiles = await mdfind('kMDItemContentType == "public.png"', {
onlyIn: '~/Downloads'
})
console.log(`Found ${imageFiles.length} PNG images`)
console.log('First 3:', imageFiles.slice(0, 3))
// Search by filename in current directory
console.log('\n3. Finding package.json files in current project:')
const packageFiles = await mdfind('', {
name: 'package.json',
onlyIn: process.cwd()
})
console.log(`Found ${packageFiles.length} package.json files`)
console.log('All matches:', packageFiles)
// Get author metadata from documents
console.log('\n4. Finding recent documents with author metadata:')
const authorDocs = await mdfind(
'kMDItemAuthors == * && kMDItemContentType == "com.adobe.pdf"',
{
attr: 'kMDItemAuthors',
onlyIn: '~/Documents'
}
)
console.log(`Found ${authorDocs.length} documents with authors`)
console.log('First 3:', authorDocs.slice(0, 3))
} catch (error) {
if (error instanceof Error && (error as MdfindError).stderr) {
console.error('Search failed:', error.message)
console.error('stderr:', (error as MdfindError).stderr)
process.exit(1)
}
throw error
}
}
void main().catch(error => {
console.error('Error:', error)
process.exit(1)
})