I found this in a 2 year old forum post: How to trash only replicants, not originals?
- Deleted from a smart group, smart rule or search results, all instances are moved to the Trash.
-
I’d like a warning if all replicants are deleted even if just one is selected. I recently discovered this behaviour and it was quite surprising. This would lead to data loss going unnoticed.
-
Is there a shortcut to delete just this single replicant? Switching between views is quite cumbersome.
My use case:
- I have a database for all my business letters and invoices.
- For my tax return, I replicate invoices and bank statements to a group “Collected Documents” containing all the files for that return.
Structure
Screenshot translated by ChatGPT
Script
If someone is interested in the details.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
use script "RegexAndStuffLib" version "1.0.7"
property globalIsDev : true
tell application id "DNtp"
activate
-- get record
local theWindow
set theWindow to think window 1
local theRecords
set theRecords to (selection of theWindow)
if length of theRecords < 1 then
error "No selected item"
end if
local createdGroup
set createdGroup to (item 1 of theRecords)
if type of createdGroup is not group then
error "No group selected"
end if
-- run code
local currentYear
set currentYear to year of (current date)
local theResult
set theResult to display dialog "Enter tax year, please" default answer currentYear
local taxYear
set taxYear to text returned of theResult
local oldName
set oldName to name of createdGroup
local newName
set newName to "für_" & taxYear
set name of createdGroup to newName
my dtLog(createdGroup, "INFO", "Change name of group", {"old-name=" & quoted form of oldName, "new-name=" & quoted form of newName})
local baseLocation
set baseLocation to (location with name of createdGroup)
-- phase 1 group
local createTaxApplicationGroup
set createTaxApplicationGroup to create location "1-Steuererklärung erstellen" in createdGroup
if createTaxApplicationGroup is missing value then
my dtLog(current group, "INFO", "Record could not be found ", {"path=" & quoted form of (location with name of createTaxApplicationGroup)})
error "Record could not be found at " & quoted form of (location with name of createTaxApplicationGroup)
end if
local receiptsGroup
set receiptsGroup to create location "Belege" in createTaxApplicationGroup
local collectedReceiptsGroup
set collectedReceiptsGroup to create location "Gesammelte Belege" in receiptsGroup
local globalGroup
set globalGroup to create location "/"
-- create search for all tax documents in database
local allTaxDocsGroupName
set allTaxDocsGroupName to "Alle Steuerunterlagen für " & taxYear & " in DB " & name of globalGroup
set allTaxDocsGroup to create record with {name:allTaxDocsGroupName, record type:smart group, search predicates:"kind:pdf {any: tags:taxes-" & taxYear & ";steuern-" & taxYear & ";mdtaxyear==" & taxYear & "}"} in receiptsGroup
if allTaxDocsGroup is missing value then
my dtLog(current group, "INFO", "Smart group could not be created ", {"name=" & allTaxDocsGroupName, "path=" & quoted form of location with name of createTaxApplicationGroup})
error "Smart group " & allTaxDocsGroupName & " could not be created at " & quoted form of location with name of receiptsGroup
end if
set search group of allTaxDocsGroup to globalGroup
-- create search for tags
local relevantReceiptsGroup
set relevantReceiptsGroup to create location "Relevante Belege" in receiptsGroup
local houseHoldServicesSearch
set houseHoldServicesSearch to create record with {name:"Haushaltsnahe Dienstleistungen", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-haushaltsnahe-dienstleistungen}"} in relevantReceiptsGroup
set search group of houseHoldServicesSearch to collectedReceiptsGroup
local kapSearch
set kapSearch to create record with {name:"KAP", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-kap}"} in relevantReceiptsGroup
set search group of kapSearch to collectedReceiptsGroup
local donationSearch
set donationSearch to create record with {name:"Spenden", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-spenden}"} in relevantReceiptsGroup
set search group of donationSearch to collectedReceiptsGroup
local devicesSearch
set devicesSearch to create record with {name:"Beruflich genutzte Geräte", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-beruflich-genutzte-geraete}"} in relevantReceiptsGroup
set search group of devicesSearch to collectedReceiptsGroup
local booksSearch
set booksSearch to create record with {name:"Fachliteratur", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-fachliteratur}"} in relevantReceiptsGroup
set search group of booksSearch to collectedReceiptsGroup
local ohterJobCostsSearch
set ohterJobCostsSearch to create record with {name:"Sonstige Werbungskosten", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-werbungskosten}"} in relevantReceiptsGroup
set search group of ohterJobCostsSearch to collectedReceiptsGroup
local otherSearch
set otherSearch to create record with {name:"Sonstiges", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-sonstiges}"} in relevantReceiptsGroup
set search group of otherSearch to collectedReceiptsGroup
-- phase 2 group
local finishTaxApplicationGroup
set finishTaxApplicationGroup to create location "2-Steuererklärung abgeben" in createdGroup
if finishTaxApplicationGroup is missing value then
my dtLog(current group, "INFO", "Record could not be found ", {"path=" & quoted form of (location with name of finishTaxApplicationGroup)})
error "Record could not be found at " & quoted form of (location with name of finishTaxApplicationGroup)
end if
-- create search for kap etc.
local submitGroup
set submitGroup to create location "Einzureichende Belege" in finishTaxApplicationGroup
local houseHoldServicesSearch
set houseHoldServicesSearch to create record with {name:"Haushaltsnahe Dienstleistungen", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-haushaltsnahe-dienstleistungen}"} in submitGroup
set search group of houseHoldServicesSearch to collectedReceiptsGroup
local noTagsSearch
set noTagsSearch to create record with {name:"Kein Steuer-Etikett zugeordnet", record type:smart group, search predicates:"kind:pdf tags!=steuern-belege-kap;steuern-belege-beruflich-genutzte-geraete;steuern-belege-haushaltsnahe-dienstleistungen;steuern-belege-fachliteratur;steuern-belege-sonstiges;steuern-belege-werbungskosten;steuern-belege-spenden"} in submitGroup
set search group of noTagsSearch to collectedReceiptsGroup
local kapSearch
set kapSearch to create record with {name:"KAP", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-kap}"} in submitGroup
set search group of kapSearch to collectedReceiptsGroup
local donationSearch
set donationSearch to create record with {name:"Spenden", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-spenden}"} in submitGroup
set search group of donationSearch to collectedReceiptsGroup
local devicesSearch
set devicesSearch to create record with {name:"Werbungskosten", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-beruflich-genutzte-geraete;steuern-belege-fachliteratur;steuern-belege-werbungskosten}"} in submitGroup
set search group of devicesSearch to collectedReceiptsGroup
local devicesSearch
set devicesSearch to create record with {name:"Gesundheit", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-gesundheit}"} in submitGroup
set search group of devicesSearch to collectedReceiptsGroup
local otherSearch
set otherSearch to create record with {name:"Sonstiges", record type:smart group, search predicates:"kind:pdf {any: tags:steuern-belege-sonstiges}"} in submitGroup
set search group of otherSearch to collectedReceiptsGroup
end tell
on dtLog(theRecord, level, msg, msgInfo)
if class of msgInfo is not list and msgInfo is not missing value then
error "Invalid definition of msgInfo in dtLog: Needs to be {}"
end if
if msgInfo is missing value then
set logMsg to "msg=" & msg
else
set logMsg to "msg=" & msg & " " & (join strings msgInfo using delimiter return)
end if
if level is not "DEBUG" then
tell application id "DNtp"
if theRecord is missing value then
log message "level=INFO " & logMsg
else
log message record theRecord info "level=INFO " & logMsg
end if
end tell
return
end if
if globalIsDev is true then
tell application id "DNtp"
if theRecord is missing value then
log message "level=INFO " & logMsg
else
log message record theRecord info "level=INFO " & logMsg
end if
end tell
end if
end dtLog



