How can a Smart Rule move new items to a particular group and then notify the user?

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.

1 Like

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.)

1 Like

Something like this works for me:

2021-02-02_10-11-18

Stephen

2 Likes

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).

The simplest scripted version is

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!). :rofl:

Stephen

Cool, thanks for the feedback :slight_smile: @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.

1 Like

I think that’s correct—and thanks for the kind comment (as well as for all the support you always give on this forum: I learn a lot from it).

Stephen

1 Like

That’s excatly my problem: I get consistent ghost notifications - particularly with triggers like Every minute or Every hour. :frowning:

This behaviour of the Smart Rules feels to me just plain wrong.

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 :slight_smile:

But why do some Smart Rumes behave teh way I expect it and otgers not? Isn’t this a local IFFF-type of thing???

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.

2 Likes

Thanks @Blanc. This explains the thinking behind the behaviour - I still think the behaviour is pretty unusual and unintuitive…

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.

1 Like

@Blanc Moving the notification into the performSmartRule handler works well - even with time based triggers. Thank you. :slight_smile:

1 Like