-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEnhanced_Archive_GUI.applescript
More file actions
709 lines (567 loc) · 64.2 KB
/
Enhanced_Archive_GUI.applescript
File metadata and controls
709 lines (567 loc) · 64.2 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
-- Enhanced AI File Organizer - Archive Management GUI with Visual Context
-- Complete archive lifecycle management with ADHD-friendly design
-- Ryan Thomson's Comprehensive File Organization System
-- Configuration
set pythonPath to "/Users/ryanthomson/py312_env/bin/python"
set organizerPath to "/Users/ryanthomson/Github/ai-file-organizer"
-- Visual Context Icons (ADHD-friendly recognition)
property SEARCH_ICON : "🔍"
property ORGANIZE_ICON : "📁"
property ARCHIVE_ICON : "🗃️"
property ACTIVE_ICON : "🔴"
property HISTORICAL_ICON : "🔵"
property REFERENCE_ICON : "🟢"
property TEMP_ICON : "🟡"
property SUCCESS_ICON : "✅"
property WARNING_ICON : "⚠️"
property ERROR_ICON : "❌"
property MIGRATION_ICON : "🚀"
property STATUS_ICON : "📊"
property GDRIVE_ICON : "☁️"
property UPLOAD_ICON : "⬆️"
-- Main Menu with Visual Context
try
set menuChoice to choose from list {¬
SEARCH_ICON & " Enhanced Search", ¬
ORGANIZE_ICON & " Quick Organize", ¬
ARCHIVE_ICON & " Archive Management", ¬
GDRIVE_ICON & " Google Drive Archive", ¬
MIGRATION_ICON & " Migration Assistant", ¬
STATUS_ICON & " System Status"} ¬
with title "AI File Organizer - Archive Edition" ¬
with prompt "Choose an action:" ¬
default items {SEARCH_ICON & " Enhanced Search"} ¬
OK button name "Select" ¬
cancel button name "Exit"
if menuChoice is false then
return -- User cancelled
end if
set selectedAction to item 1 of menuChoice
-- Route to appropriate function based on selection
if selectedAction contains "Enhanced Search" then
enhancedSearch()
else if selectedAction contains "Quick Organize" then
quickOrganize()
else if selectedAction contains "Archive Management" then
archiveManagement()
else if selectedAction contains "Google Drive Archive" then
googleDriveArchive()
else if selectedAction contains "Migration Assistant" then
migrationAssistant()
else if selectedAction contains "System Status" then
systemStatus()
end if
on error errMsg number errNum
if errNum is not -128 then -- User didn't cancel
display dialog ERROR_ICON & " System Error: " & errMsg with title "AI File Organizer Error" buttons {"OK"} default button "OK" with icon stop
end if
end try
-- Enhanced Search with Archive Context
on enhancedSearch()
try
set searchQuery to text returned of (display dialog SEARCH_ICON & " Search across ALL your files (active + archived):" with title "Enhanced AI File Search" default answer "" buttons {"Cancel", "Search"} default button "Search" with icon note giving up after 300)
if searchQuery is not "" then
-- Search scope selection with visual context
set searchScope to choose from list {¬
ACTIVE_ICON & " Active Projects Only", ¬
HISTORICAL_ICON & " Archives Only", ¬
SEARCH_ICON & " Everything (Active + Archive)", ¬
REFERENCE_ICON & " Templates & References"} ¬
with title "Search Scope" ¬
with prompt SEARCH_ICON & " Where should I search for: " & searchQuery ¬
default items {SEARCH_ICON & " Everything (Active + Archive)"}
if searchScope is false then return
set selectedScope to item 1 of searchScope
-- Search mode selection
set searchMode to choose from list {"🚀 Auto (Smart)", "⚡ Fast (Keywords)", "🧠 Semantic (AI Understanding)"} ¬
with title "Search Mode" ¬
with prompt "How should I search?" ¬
default items {"🚀 Auto (Smart)"}
if searchMode is false then return
-- Convert selections to parameters
set modeParam to "auto"
if item 1 of searchMode contains "Fast" then
set modeParam to "fast"
else if item 1 of searchMode contains "Semantic" then
set modeParam to "semantic"
end if
set scopeParam to ""
if selectedScope contains "Active Projects" then
set scopeParam to " --scope active"
else if selectedScope contains "Archives" then
set scopeParam to " --scope archive"
else if selectedScope contains "Templates" then
set scopeParam to " --scope reference"
end if
-- Show progress notification
display notification SEARCH_ICON & " Searching: " & searchQuery with title "AI File Organizer" subtitle "Analyzing content across your file ecosystem..."
-- Execute search
set searchCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " enhanced_librarian.py search " & quoted form of searchQuery & " --mode " & modeParam & scopeParam & " --limit 10"
set searchResults to do shell script searchCommand
-- Format and display results with archive context
set formattedResults to formatArchiveResults(searchResults, selectedScope)
-- Results dialog with archive actions
set resultDialog to display dialog formattedResults with title (SEARCH_ICON & " Results: " & searchQuery) buttons {MIGRATION_ICON & " Migrate Files", SEARCH_ICON & " New Search", SUCCESS_ICON & " Done"} default button SUCCESS_ICON & " Done" with icon note giving up after 60
set buttonResult to button returned of resultDialog
if buttonResult contains "New Search" then
enhancedSearch()
else if buttonResult contains "Migrate Files" then
migrationAssistant()
end if
end if
on error errMsg number errNum
if errNum is not -128 then
display notification ERROR_ICON & " Search failed: " & errMsg with title "AI File Organizer" sound name "Basso"
end if
end try
end enhancedSearch
-- Quick Organize with Archive-Aware Classification
on quickOrganize()
try
-- Directory selection with visual context
set organizeChoice to choose from list {¬
TEMP_ICON & " Downloads (7+ day old files)", ¬
TEMP_ICON & " Desktop (7+ day old files)", ¬
ORGANIZE_ICON & " Custom Directory", ¬
ARCHIVE_ICON & " Review Archive Candidates"} ¬
with title "Quick Organize" ¬
with prompt ORGANIZE_ICON & " What would you like to organize?" ¬
default items {TEMP_ICON & " Downloads (7+ day old files)"}
if organizeChoice is false then return
set selectedChoice to item 1 of organizeChoice
-- Mode selection with ADHD-friendly options
set organizeMode to choose from list {¬
SUCCESS_ICON & " Preview Only (Safe - No Files Moved)", ¬
WARNING_ICON & " Organize Files (Live Mode)"} ¬
with title "Organization Mode" ¬
with prompt "Choose mode:" ¬
default items {SUCCESS_ICON & " Preview Only (Safe - No Files Moved)"}
if organizeMode is false then return
set selectedMode to item 1 of organizeMode
-- Determine command parameters
set modeParam to "--dry-run"
if selectedMode contains "Live Mode" then
set modeParam to "--live"
end if
set directoryParam to ""
if selectedChoice contains "Downloads" then
set directoryParam to "~/Downloads"
else if selectedChoice contains "Desktop" then
set directoryParam to "~/Desktop"
else if selectedChoice contains "Custom Directory" then
set customDir to choose folder with prompt ORGANIZE_ICON & " Select directory to organize:"
set directoryParam to quoted form of POSIX path of customDir
else if selectedChoice contains "Archive Candidates" then
archiveManagement()
return
end if
-- Show progress notification
if selectedMode contains "Preview" then
display notification ORGANIZE_ICON & " Analyzing files for organization..." with title "AI File Organizer" subtitle "Preview mode - no files will be moved"
else
display notification WARNING_ICON & " Organizing files..." with title "AI File Organizer" subtitle "Live mode - files will be moved to appropriate folders"
end if
-- Execute organization
set organizeCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " interactive_organizer.py organize " & modeParam
if directoryParam is not "" then
set organizeCommand to organizeCommand & " --directory " & directoryParam
end if
set organizeResults to do shell script organizeCommand
-- Show results with archive context
set formattedResults to formatOrganizeResults(organizeResults, selectedMode)
display dialog formattedResults with title (ORGANIZE_ICON & " Organization Results") buttons {ARCHIVE_ICON & " Archive Management", ORGANIZE_ICON & " Organize More", SUCCESS_ICON & " Done"} default button SUCCESS_ICON & " Done" with icon note giving up after 45
set buttonResult to button returned of result
if buttonResult contains "Organize More" then
quickOrganize()
else if buttonResult contains "Archive Management" then
archiveManagement()
end if
on error errMsg number errNum
if errNum is not -128 then
display notification ERROR_ICON & " Organization failed: " & errMsg with title "AI File Organizer" sound name "Basso"
end if
end try
end quickOrganize
-- Archive Management with Lifecycle Controls
on archiveManagement()
try
set archiveChoice to choose from list {¬
HISTORICAL_ICON & " Review Archive Suggestions", ¬
ARCHIVE_ICON & " Archive Lifecycle Status", ¬
ACTIVE_ICON & " Find Files Ready to Archive", ¬
SUCCESS_ICON & " Execute Archive Actions"} ¬
with title "Archive Management" ¬
with prompt ARCHIVE_ICON & " Archive management options:" ¬
default items {HISTORICAL_ICON & " Review Archive Suggestions"}
if archiveChoice is false then return
set selectedChoice to item 1 of archiveChoice
if selectedChoice contains "Archive Suggestions" then
-- Get archive suggestions
display notification ARCHIVE_ICON & " Analyzing files for archiving..." with title "AI File Organizer" subtitle "Finding files ready for historical archive"
set suggestCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " archive_lifecycle_manager.py suggest --limit 10"
set suggestions to do shell script suggestCommand
set formattedSuggestions to formatArchiveSuggestions(suggestions)
display dialog formattedSuggestions with title (ARCHIVE_ICON & " Archive Suggestions") buttons {SUCCESS_ICON & " Execute Selected", ARCHIVE_ICON & " More Options", WARNING_ICON & " Cancel"} default button WARNING_ICON & " Cancel" with icon note giving up after 60
else if selectedChoice contains "Lifecycle Status" then
-- Show archive system status
set statusCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " archive_lifecycle_manager.py status"
set statusResults to do shell script statusCommand
display dialog STATUS_ICON & " Archive System Status:" & return & return & statusResults with title "Archive Lifecycle Status" buttons {ARCHIVE_ICON & " Manage Archives", SUCCESS_ICON & " Done"} default button SUCCESS_ICON & " Done" with icon note
else if selectedChoice contains "Ready to Archive" then
-- Find files ready for archiving based on age and content
display notification SEARCH_ICON & " Finding files ready for archive..." with title "AI File Organizer" subtitle "Analyzing file age and content indicators"
set findCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " archive_lifecycle_manager.py suggest --directory ~/Documents --limit 15"
set findResults to do shell script findCommand
display dialog HISTORICAL_ICON & " Files Ready for Archive:" & return & return & findResults with title "Archive Candidates" buttons {MIGRATION_ICON & " Migrate to Archive", SEARCH_ICON & " Search More", SUCCESS_ICON & " Done"} default button SUCCESS_ICON & " Done" with icon note
end if
on error errMsg number errNum
if errNum is not -128 then
display notification ERROR_ICON & " Archive management failed: " & errMsg with title "AI File Organizer" sound name "Basso"
end if
end try
end archiveManagement
-- Migration Assistant for Google Drive Integration
on migrationAssistant()
try
set migrationChoice to choose from list {¬
MIGRATION_ICON & " Analyze Existing Structure", ¬
MIGRATION_ICON & " Create Migration Plan", ¬
SUCCESS_ICON & " Execute Migration Phase", ¬
STATUS_ICON & " Generate Migration Report"} ¬
with title "Migration Assistant" ¬
with prompt MIGRATION_ICON & " Google Drive & File Migration:" ¬
default items {MIGRATION_ICON & " Analyze Existing Structure"}
if migrationChoice is false then return
set selectedChoice to item 1 of migrationChoice
if selectedChoice contains "Analyze Existing" then
-- Choose directory to analyze
set sourceDir to choose folder with prompt SEARCH_ICON & " Select directory to analyze for migration:"
set sourcePath to POSIX path of sourceDir
display notification MIGRATION_ICON & " Analyzing file structure..." with title "Migration Assistant" subtitle "Understanding your current organization"
set analyzeCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " google_drive_migration.py analyze --source " & quoted form of sourcePath
set analysisResults to do shell script analyzeCommand
display dialog SEARCH_ICON & " Analysis Results:" & return & return & analysisResults with title "Structure Analysis" buttons {MIGRATION_ICON & " Create Plan", MIGRATION_ICON & " Generate Report", SUCCESS_ICON & " Done"} default button MIGRATION_ICON & " Create Plan" with icon note giving up after 60
else if selectedChoice contains "Migration Plan" then
set sourceDir to choose folder with prompt MIGRATION_ICON & " Select source directory for migration plan:"
set sourcePath to POSIX path of sourceDir
display notification MIGRATION_ICON & " Creating migration plan..." with title "Migration Assistant" subtitle "Designing ADHD-friendly migration strategy"
set planCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " google_drive_migration.py plan --source " & quoted form of sourcePath
set planResults to do shell script planCommand
display dialog MIGRATION_ICON & " Migration Plan:" & return & return & planResults with title "Migration Strategy" buttons {SUCCESS_ICON & " Execute Phase 1", STATUS_ICON & " Generate Report", WARNING_ICON & " Cancel"} default button SUCCESS_ICON & " Execute Phase 1" with icon note
else if selectedChoice contains "Generate Migration Report" then
set sourceDir to choose folder with prompt STATUS_ICON & " Select directory for comprehensive migration report:"
set sourcePath to POSIX path of sourceDir
display notification STATUS_ICON & " Generating comprehensive report..." with title "Migration Assistant" subtitle "Creating detailed migration analysis"
set reportCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " google_drive_migration.py report --source " & quoted form of sourcePath
set reportPath to do shell script reportCommand
display dialog SUCCESS_ICON & " Migration Report Generated!" & return & return & "📄 Report saved to:" & return & reportPath & return & return & "This report contains:" & return & "• Complete file analysis" & return & "• ADHD-friendly migration plan" & return & "• Step-by-step commands" & return & "• Safety recommendations" with title "Report Complete" buttons {SEARCH_ICON & " Open Report", SUCCESS_ICON & " Done"} default button SUCCESS_ICON & " Done" with icon note
end if
on error errMsg number errNum
if errNum is not -128 then
display notification ERROR_ICON & " Migration failed: " & errMsg with title "Migration Assistant" sound name "Basso"
end if
end try
end migrationAssistant
-- System Status with Archive Context
on systemStatus()
try
display notification STATUS_ICON & " Gathering system status..." with title "AI File Organizer" subtitle "Checking archive and search systems"
-- Get comprehensive status
set statusCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " archive_lifecycle_manager.py status"
set archiveStatus to do shell script statusCommand
-- Also get background monitor status if available
try
set monitorCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " background_monitor.py status"
set monitorStatus to do shell script monitorCommand
on error
set monitorStatus to "Background monitor not running"
end try
set fullStatus to STATUS_ICON & " Archive System Status:" & return & return & archiveStatus & return & return & STATUS_ICON & " Background Monitor:" & return & monitorStatus
set statusDialog to display dialog fullStatus with title "AI File Organizer - System Status" buttons {MIGRATION_ICON & " Start Migration", ORGANIZE_ICON & " Quick Organize", SUCCESS_ICON & " Done"} default button SUCCESS_ICON & " Done" with icon note giving up after 60
set buttonResult to button returned of statusDialog
if buttonResult contains "Start Migration" then
migrationAssistant()
else if buttonResult contains "Quick Organize" then
quickOrganize()
end if
on error errMsg number errNum
if errNum is not -128 then
display notification ERROR_ICON & " Status check failed: " & errMsg with title "AI File Organizer" sound name "Basso"
end if
end try
end systemStatus
-- Google Drive Archive with Intelligent Lifecycle Management
on googleDriveArchive()
try
set gdriveChoice to choose from list {¬
UPLOAD_ICON & " Upload Single File (Archive-Aware)", ¬
GDRIVE_ICON & " Bulk Upload Directory (ADHD-Friendly)", ¬
STATUS_ICON & " Check Google Drive Status", ¬
SUCCESS_ICON & " Setup Google Drive Authentication"} ¬
with title "Google Drive Archive" ¬
with prompt GDRIVE_ICON & " Choose Google Drive action:" ¬
default items {UPLOAD_ICON & " Upload Single File (Archive-Aware)"}
if gdriveChoice is false then return
set selectedChoice to item 1 of gdriveChoice
if selectedChoice contains "Upload Single File" then
-- Single file upload with archive awareness
set fileToUpload to choose file with prompt UPLOAD_ICON & " Choose file for intelligent archive upload:"
set filePath to POSIX path of fileToUpload
-- Lifecycle stage selection (optional)
set stageChoice to choose from list {¬
ACTIVE_ICON & " Auto-Detect Stage (Recommended)", ¬
ACTIVE_ICON & " Force Active Project", ¬
HISTORICAL_ICON & " Force Archive", ¬
REFERENCE_ICON & " Force Deep Storage"} ¬
with title "Archive Stage" ¬
with prompt "How should this file be classified?" ¬
default items {ACTIVE_ICON & " Auto-Detect Stage (Recommended)"}
if stageChoice is false then return
set selectedStage to item 1 of stageChoice
set stageParam to ""
if selectedStage contains "Force Active" then
set stageParam to " --stage active"
else if selectedStage contains "Force Archive" then
set stageParam to " --stage archive_candidate"
else if selectedStage contains "Force Deep Storage" then
set stageParam to " --stage deep_storage_candidate"
end if
-- Auto-delete option
set deleteChoice to choose from list {¬
SUCCESS_ICON & " Keep Local File (Safe)", ¬
WARNING_ICON & " Delete After Upload (Space Saving)"} ¬
with title "Local File Handling" ¬
with prompt "What should happen to the local file?" ¬
default items {SUCCESS_ICON & " Keep Local File (Safe)"}
if deleteChoice is false then return
set deleteParam to ""
if item 1 of deleteChoice contains "Delete After Upload" then
set deleteParam to " --auto-delete"
end if
-- Execute upload
display notification GDRIVE_ICON & " Uploading with intelligent archive analysis..." with title "Google Drive Archive" subtitle "Analyzing file content and lifecycle..."
set uploadCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " gdrive_librarian.py archive-upload --file " & quoted form of filePath & stageParam & deleteParam
set uploadResults to do shell script uploadCommand
-- Show results
display dialog GDRIVE_ICON & " Upload Results:" & return & return & uploadResults with title "Google Drive Upload Complete" buttons {GDRIVE_ICON & " Upload Another", SUCCESS_ICON & " Done"} default button SUCCESS_ICON & " Done" with icon note giving up after 60
set buttonResult to button returned of result
if buttonResult contains "Upload Another" then
googleDriveArchive()
end if
else if selectedChoice contains "Bulk Upload Directory" then
-- Bulk upload with ADHD-friendly batch processing
set sourceDirectory to choose folder with prompt GDRIVE_ICON & " Select directory for bulk archive upload:"
set sourcePath to POSIX path of sourceDirectory
-- Batch size selection (ADHD-friendly)
set batchChoice to choose from list {¬
SUCCESS_ICON & " Small Batch (10 files) - Easy", ¬
WARNING_ICON & " Medium Batch (20 files) - Standard", ¬
ERROR_ICON & " Large Batch (50 files) - Advanced"} ¬
with title "Batch Size" ¬
with prompt "How many files should I process at once?" ¬
default items {WARNING_ICON & " Medium Batch (20 files) - Standard"}
if batchChoice is false then return
set selectedBatch to item 1 of batchChoice
set maxFiles to "20"
if selectedBatch contains "Small Batch" then
set maxFiles to "10"
else if selectedBatch contains "Large Batch" then
set maxFiles to "50"
end if
-- Mode selection
set modeChoice to choose from list {¬
SUCCESS_ICON & " Preview Mode (Safe Analysis)", ¬
WARNING_ICON & " Upload Mode (Execute Upload)"} ¬
with title "Operation Mode" ¬
with prompt "How should I process the files?" ¬
default items {SUCCESS_ICON & " Preview Mode (Safe Analysis)"}
if modeChoice is false then return
set selectedMode to item 1 of modeChoice
set liveParam to ""
if selectedMode contains "Upload Mode" then
set liveParam to " --live"
end if
-- Execute bulk upload
if selectedMode contains "Preview" then
display notification GDRIVE_ICON & " Analyzing directory for bulk upload..." with title "Google Drive Archive" subtitle "Preview mode - no files will be uploaded"
else
display notification WARNING_ICON & " Starting bulk upload..." with title "Google Drive Archive" subtitle "Upload mode - files will be uploaded to Google Drive"
end if
set bulkCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " gdrive_librarian.py bulk-upload --directory " & quoted form of sourcePath & " --max-files " & maxFiles & liveParam
set bulkResults to do shell script bulkCommand
-- Show results
display dialog GDRIVE_ICON & " Bulk Upload Results:" & return & return & bulkResults with title "Bulk Upload Complete" buttons {GDRIVE_ICON & " Upload More", ARCHIVE_ICON & " Manage Archives", SUCCESS_ICON & " Done"} default button SUCCESS_ICON & " Done" with icon note giving up after 60
set buttonResult to button returned of result
if buttonResult contains "Upload More" then
googleDriveArchive()
else if buttonResult contains "Manage Archives" then
archiveManagement()
end if
else if selectedChoice contains "Check Google Drive Status" then
-- Check Google Drive connection and capabilities
display notification STATUS_ICON & " Checking Google Drive connection..." with title "Google Drive Archive" subtitle "Validating authentication and features"
set statusCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " gdrive_librarian.py status"
set statusResults to do shell script statusCommand
-- Also get storage info
try
set infoCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " gdrive_librarian.py info"
set infoResults to do shell script infoCommand
set fullStatus to statusResults & return & return & "💾 Storage Information:" & return & infoResults
on error
set fullStatus to statusResults & return & return & "💾 Storage Information: Not available (authentication needed)"
end try
display dialog STATUS_ICON & " Google Drive Status:" & return & return & fullStatus with title "Google Drive Archive Status" buttons {GDRIVE_ICON & " Setup Auth", STATUS_ICON & " Refresh", SUCCESS_ICON & " Done"} default button SUCCESS_ICON & " Done" with icon note giving up after 60
else if selectedChoice contains "Setup Google Drive Authentication" then
-- Guide user through authentication setup
set authDialog to display dialog SUCCESS_ICON & " Google Drive Authentication Setup" & return & return & "To use Google Drive archive features, you need to:" & return & return & "1. Set up Google Drive API credentials" & return & "2. Authenticate your account" & return & "3. Create folder structure" & return & return & "Would you like to start the authentication process?" with title "Google Drive Setup" buttons {WARNING_ICON & " Cancel", SUCCESS_ICON & " Start Setup"} default button SUCCESS_ICON & " Start Setup" with icon note
set buttonResult to button returned of authDialog
if buttonResult contains "Start Setup" then
display notification SUCCESS_ICON & " Starting Google Drive authentication..." with title "Google Drive Archive" subtitle "Follow the authentication prompts"
set authCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " gdrive_librarian.py auth"
try
set authResults to do shell script authCommand
display dialog SUCCESS_ICON & " Authentication Results:" & return & return & authResults & return & return & "Next step: Create folder structure?" with title "Authentication Complete" buttons {GDRIVE_ICON & " Create Folders", SUCCESS_ICON & " Done"} default button GDRIVE_ICON & " Create Folders" with icon note
set buttonResult to button returned of result
if buttonResult contains "Create Folders" then
set folderCommand to "cd " & quoted form of organizerPath & " && " & pythonPath & " gdrive_librarian.py create-folders"
set folderResults to do shell script folderCommand
display dialog GDRIVE_ICON & " Folder Creation Results:" & return & return & folderResults with title "Setup Complete" buttons {SUCCESS_ICON & " Done"} default button SUCCESS_ICON & " Done" with icon note
end if
on error errMsg
display dialog ERROR_ICON & " Authentication Error:" & return & return & errMsg & return & return & "Please check your credentials and try again." with title "Authentication Failed" buttons {SUCCESS_ICON & " OK"} default button SUCCESS_ICON & " OK" with icon stop
end try
end if
end if
on error errMsg number errNum
if errNum is not -128 then
display notification ERROR_ICON & " Google Drive operation failed: " & errMsg with title "Google Drive Archive" sound name "Basso"
end if
end try
end googleDriveArchive
-- Format search results with archive context indicators
on formatArchiveResults(rawResults, searchScope)
try
set resultLines to paragraphs of rawResults
set formattedText to ""
set resultCount to 0
set isInResults to false
repeat with currentLine in resultLines
set lineText to currentLine as string
-- Check if we're in the results section
if lineText contains "Found" and lineText contains "results:" then
set isInResults to true
set formattedText to formattedText & lineText & return & return
else if isInResults then
-- Format individual results with archive context
if lineText starts with "[" and lineText contains "]" then
set resultCount to resultCount + 1
if resultCount ≤ 7 then -- Show more results for archive context
-- Add visual context based on file location
if lineText contains "ACTIVE_PROJECTS" then
set formattedText to formattedText & ACTIVE_ICON & " " & lineText & return
else if lineText contains "ARCHIVE_HISTORICAL" then
set formattedText to formattedText & HISTORICAL_ICON & " " & lineText & return
else if lineText contains "REFERENCE_LIBRARY" then
set formattedText to formattedText & REFERENCE_ICON & " " & lineText & return
else
set formattedText to formattedText & lineText & return
end if
end if
else if lineText contains "📊" or lineText contains "🧠" or lineText contains "🏷️" or lineText contains "📅" then
if resultCount ≤ 7 then
set formattedText to formattedText & " " & lineText & return
end if
end if
end if
end repeat
if resultCount > 7 then
set formattedText to formattedText & return & "... and " & (resultCount - 7) & " more results"
end if
-- Add search scope context
set scopeContext to item 1 of searchScope
set formattedText to formattedText & return & return & "📍 Search Scope: " & scopeContext
-- Add archive legend
set formattedText to formattedText & return & return & "📖 Legend:" & return & ACTIVE_ICON & " Active Projects " & HISTORICAL_ICON & " Historical Archive " & REFERENCE_ICON & " Reference Library"
if formattedText contains "Found 0 results" or resultCount = 0 then
return ERROR_ICON & " No results found." & return & return & "💡 Try:" & return & "• Different keywords" & return & "• Broader search scope" & return & "• Migration assistant to organize files first"
else
return formattedText
end if
on error
return WARNING_ICON & " Could not format results properly." & return & return & rawResults
end try
end formatArchiveResults
-- Format organization results with archive awareness
on formatOrganizeResults(rawResults, organizationMode)
try
set resultLines to paragraphs of rawResults
set formattedText to ""
-- Add mode context
if organizationMode contains "Preview" then
set formattedText to SUCCESS_ICON & " PREVIEW MODE - No files were moved" & return & return
else
set formattedText to WARNING_ICON & " LIVE MODE - Files have been organized" & return & return
end if
-- Process results and add archive context
repeat with currentLine in resultLines
set lineText to currentLine as string
-- Enhance output with visual context
if lineText contains "Moved to:" then
if lineText contains "ACTIVE_PROJECTS" then
set formattedText to formattedText & ACTIVE_ICON & " " & lineText & return
else if lineText contains "ARCHIVE" then
set formattedText to formattedText & HISTORICAL_ICON & " " & lineText & return
else
set formattedText to formattedText & lineText & return
end if
else if lineText contains "ADHD importance:" then
set formattedText to formattedText & " ⭐ " & lineText & return
else if lineText contains "confidence" or lineText contains "%" then
set formattedText to formattedText & " 📊 " & lineText & return
else if lineText is not "" then
set formattedText to formattedText & lineText & return
end if
end repeat
-- Add summary and next steps
set formattedText to formattedText & return & "🔄 Next Steps:" & return & "• Review results above" & return & "• Use Archive Management for lifecycle control" & return & "• Search files with enhanced context awareness"
return formattedText
on error
return WARNING_ICON & " Could not format results properly." & return & return & rawResults
end try
end formatOrganizeResults
-- Format archive suggestions with ADHD-friendly priorities
on formatArchiveSuggestions(rawSuggestions)
try
set suggestionLines to paragraphs of rawSuggestions
set formattedText to ARCHIVE_ICON & " Files Ready for Archive:" & return & return
set suggestionCount to 0
repeat with currentLine in suggestionLines
set lineText to currentLine as string
if lineText contains "Age:" and lineText contains "days" then
set suggestionCount to suggestionCount + 1
if suggestionCount ≤ 5 then -- Limit for ADHD manageability
-- Extract importance level for visual context
if lineText contains "Importance: 1" or lineText contains "Importance: 2" then
set formattedText to formattedText & HISTORICAL_ICON & " " & lineText & return
else if lineText contains "Importance: 8" or lineText contains "Importance: 9" then
set formattedText to formattedText & WARNING_ICON & " " & lineText & return
else
set formattedText to formattedText & ARCHIVE_ICON & " " & lineText & return
end if
end if
else if lineText contains "💡" or lineText contains "Reasoning:" then
if suggestionCount ≤ 5 then
set formattedText to formattedText & " " & lineText & return
end if
end if
end repeat
if suggestionCount > 5 then
set formattedText to formattedText & return & "... and " & (suggestionCount - 5) & " more suggestions"
end if
-- Add ADHD-friendly guidance
set formattedText to formattedText & return & return & "🧠 ADHD-Friendly Tips:" & return & WARNING_ICON & " High importance (8-9): Review carefully" & return & ARCHIVE_ICON & " Medium importance (5-7): Good archive candidates" & return & HISTORICAL_ICON & " Low importance (1-4): Safe to archive"
return formattedText
on error
return WARNING_ICON & " Could not format suggestions properly." & return & return & rawSuggestions
end try
end formatArchiveSuggestions