I need to implement an automatic filing system for some special documents:
When theses documents arrive in the Inbox I need to move them to a special group and then - that’s important - notify the user either with a Ding sound or a macOS notification.
How can I do this?
ps: I tried in the “Perform the following actions” part of the Smart Rule two actions, first the “Move” action and then the DIng, but this approach doesn’t work as outlined in this thread.
It’s simple enough to do that; in your smart rule add an additional action to execute this embedded script:
on performSmartRule(theRecords)
tell application id "DNtp"
repeat with theRecord in theRecords
set theName to name of theRecord
set theDestination to "Name of group you are moving to"
set theTitle to "The name of your rule"
set theDialog to ("File: " & theName & "
Group: " & theDestination)
display notification theDialog with title theTitle
end repeat
end tell
end performSmartRule
Obviously you can adapt that to suit your needs; you could, for example put the display notification part after the end repeat and use a counter to get the number of records, then simply showing the number moved in the notification. Equally, you can make things more complex and do the whole thing in script (i.e. moving the file etc.)
Do you not get ghost notifications, Stephen? My experience is that all actions in a smart rule will be performed, regardless of the number of files the smart rule picks up - i.e. if the rule finds no files 0 documents will be moved, 0 documents will be filed, and a notification will display (showing 0, if you used a counter).
on performSmartRule(theRecords)
tell application id "DNtp"
if (count of theRecords) > 0 then
display notification "I did something"
end if
end tell
end performSmartRule
No - no ghost notifications for me. I have a number of smart rules that check new imports and file accordingly. If none fit I get no notification. If one fits I get the appropriate notification.
I can’t possibly be doing anything sophisticated because I’m a basic user who uses scripts only if written by others (like you, you may recall!).
Cool, thanks for the feedback @cgrunenberg so do notifications in smart rules behave differently to bouncing icons and sounds?
(Let me go on record saying I think you, Stephen, are more advanced than you might credit yourself with being.)
Edit: the difference is in the trigger for the rule; in the thread @halloleo references, the rule was triggering on an action which does not require the presence of a document (such as on Time or on Sync); those rules process regardless of the document count - my script will help on those cases. Rules which require a document (eg on Import) apparently behave differently and can be processed as @Stephen_C suggests.
Irrespective of whether it feels good or not, there will actually be a good reason for it. And the problem is simple to solve with one of the two scripts I posted, or an adaption of either. Try it
I explained my understanding of that in the edit to my post above; my guess is that some ppl want feedback, as it shows them that the rule has triggered. If you imagine a rule running monthly, that might be reasonable. For a rule running every minute it obviously isn’t.
I tripped over it too, so I guess it wasn’t intuitive for me either. But I do try to practice a solution-oriented approach rather than a problem-oriented one, and solved the problem by applying my script to all applicable rules. If you need any help doing that do post back - otherwise it would be nice to hear whether your problem was solved this way too. All the best.
Edit: the difference is in the trigger for the rule; in the thread @halloleo references, the rule was triggering on an action which does not require the presence of a document (such as on Time or on Sync); those rules process regardless of the document count - my script will help on those cases. Rules which require a document (eg on Import) apparently behave differently and can be processed as @Stephen_C suggests.
This tripped me up recently–I set up a smart rule to file some items in newly created groups as they came in–and set it to run after sync, assuming it would only run if there were also matching items–fortunately, I caught it after it had created only a few dozen empty groups…but I see the benefit to having interval-based rules running regardless of document matches.