4

Print Mail Rules?

 2 years ago
source link: https://forums.macrumors.com/threads/print-mail-rules.2336495/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Print Mail Rules?

Got a tip for us? Let us know

jdw13

macrumors regular

Original poster

Oct 2, 2015

Boston, Maine, Chile

Is it possible to somehow print out the Rules from Mail/Preferences/Rules?
I would like to peruse and organize my long list.
One nice thing about using Thunderbird was that the mail filters were stored a a human-readable ASCII file.

Artiste212

macrumors member

Aug 26, 2012

This isn't what you were probably hoping to hear, but there is a workaround.

Download Owl OCR and use the free version to take a screnshot and use it's OCR to convert to text or a readable PDF. Either way, you can copy the rules text to another document.

NoBoMac

Moderator
Staff member

Jul 1, 2014

3,712

1,916

Not at my Mac, and another not what you want to hear type answer, but believe can print the plist file under account's Library/Mail folder structure. File ends with .plist and has "Rules" in the name.

Spotlight search should find it, or from Terminal: find ~/Library/Mail -type f -iname '*rule*.plist'

Now, the plist will be in XML format, so won't be a straight forward read.

jdw13

macrumors regular

Original poster

Oct 2, 2015

Boston, Maine, Chile

They appear to reside in directory
~/Library/Mail/V9/MailData
as
  • SyncedRules.plist
  • RulesActiveState.plist
  • UnsyncedRules.plist
and

/usr/libexec/PlistBuddy -c print <filename> or /usr/bin/plutil -p <filename>
can show human-readable contents but I cannot find anything that parses the files into nicely formatted text as in the rule definitions themselves. I guess that what I want to see may require code to parse multiple plist files, as the Mail program does. Perhaps someone has written such a utility?

BrianBaughn

macrumors G3

Feb 13, 2011

8,317

1,634

Baltimore, Maryland

Xcode, a huge download from Apple, will open .plist files but I don't know what the rules would look like or if they'd be printable.

Maybe someone can do a test.

jdw13

macrumors regular

Original poster

Oct 2, 2015

Boston, Maine, Chile

It would be nice to be able to print out all the Rules as you see them in Preferences, but I have what I need for now.

Since I am primarily interested seeing the Rules name and destination folder for each rules, I wrote a simple shell script to parse the syncedRules.plist file and print out this info. This works because the plist file has the Rules in the order they are applied. The script just parses the plist file without using PlistBuddy or plutil, although the script would have been simpiler using either of these utilities.

Although others may think me nuts for having about 300 Mail rules, I've been dealing with email this way for ~40 years and don't want to change now...

Artiste212

macrumors member

Aug 26, 2012

It would be nice to be able to print out all the Rules as you see them in Preferences, but I have what I need for now.

Since I am primarily interested seeing the Rules name and destination folder for each rules, I wrote a simple shell script to parse the syncedRules.plist file and print out this info. This works because the plist file has the Rules in the order they are applied. The script just parses the plist file without using PlistBuddy or plutil, although the script would have been simpiler using either of these utilities.

Although others may think me nuts for having about 300 Mail rules, I've been dealing with email this way for ~40 years and don't want to change now...
Could you post the script you wrote? I've held off on writing many more rules because worried I'd lose track of them.

I have about 50 rules in Gmail, and I've copied and pasted them all into a spreadsheet. Interestingly, Google doesn't guarantee they are executed in order, so although they have the advantage of being server-side, they're not really as useful as they could be. I've also noticed that they don't always work -- maybe about 98% of the time they do.

I mainly take advantage of Gmail's categories and assign standard labels to email in each category. This allows separating my Apple Mail inbox into primary, updates, and promotions. I've let this happen in Gmail for two reasons:
1. I didn't want to write another 70 rules in Apple Mail without being able to view them all clearly
2. Sometimes I'm at work using only a required PC, and need to read my personal email. I need Gmail to be usable in that context.

jdw13

macrumors regular

Original poster

Oct 2, 2015

Boston, Maine, Chile

Sure, but keep in mind it has very limited functionality to do just what I need.
It is an 'old-school' sh shell script and assumes that your Rules syncedRules and UnsyncedRules plist files are in the default location.
So if your data are in another location you need to change the line
inDir=~/Library/Mail/V9/MailData
The usage is very simple from the CLI. If you provide an arg, it will parse Unsynced Rules, otherwise your user-defined.
YMMV, so user beware. At least it should do no harm as it is read-only.
Just download and put in your execution path or call directly from Terminal or your favorite shell program.
Output goes to your screen. Example directing output to file:
$ do.showMailRules > MailRules.txt $ less MailRules.txt reading from Mail directory: /Users/jw/Library/Mail/V9/MailData Sat Mar 5 11:02:45 EST 2022 ...................................... usps -> imap://jdw.js13%40gmail.com/USPS bankofamerica.com -> imap://johnwiggins%40mac.com/bankofamerica.com Tablet -> imap://jdw.js13%40gmail.com/Tablet ...snip... VUDU Forums -> imap://johnwiggins%40mac.com/VUDU%20forums WhiteHouse -> imap://johnwiggins%40mac.com/WhiteHouse me -> imap://johnwiggins%40mac.com/family/me DELETE MSG -> Bank of America -> imap://johnwiggins%40mac.com/Bank%20of%20America%20Alert Junk_ -> Junk ...................................... 303 Rules in syncedRules.plist (/Users/jw/Library/Mail/V9/MailData) Sat Mar 5 11:03:21 EST 2022 version: do.showMailRules,v 1.3 2022/03/05 12:29:14 jw Exp $ (END)

NOTE: I had to add extension txt in order to get the forum to upload the file so after you download, you should:
mv do.showMailRules.txt do.showMailRules

P.S. If the file is not executable, you will need to

$ chmod 755 do.showMailRules
or similar command from your shell. Once the script is executable, you may see the following error
do.showMailRules reading from Mail directory: /Users/<YourUserName>/Library/Mail/V9/MailData Sun Mar 6 08:55:49 EST 2022 <Path>/do.showMailRules: line 85: /Users/<YourUserName>/Library/Mail/V9/MailData/SyncedRules.plist: Operation not permitted ...snip...
If so, the program you are using to serve up the shell, .e.g. Terminal, iTerm2, XQuartz, does not have permission to view files in ~/Library. To read the plist files, you need configure your server program to have full disk access to read the plist files:
  • System Preferences :
  • Security & Privacy :
  • Full Disk Access :
and add "Terminal" or whatever program you are using to provide shell in which to run the script.

Attachments

  • do.showMailRules.txt
    2.3 KB · Views: 5
Last edited: Yesterday at 8:40 AM

Reactions: Artiste212

Artiste212

macrumors member

Aug 26, 2012

Sure, but keep in mind it has very limited functionality to do just what I need.
It is an 'old-school' sh shell script and assumes that your Rules syncedRules and UnsyncedRules plist files are in the default location.
So if your data are in another location you need to change the line
inDir=~/Library/Mail/V9/MailData
The usage is very simple from the CLI. If you provide an arg, it will parse Unsynced Rules, otherwise your user-defined.
YMMV, so user beware. At least it should do no harm as it is read-only.
Just download and put in your execution path or call directly from Terminal or your favorite shell program.
Output goes to your screen. Example directing output to file:
$ do.showMailRules > MailRules.txt $ less MailRules.txt reading from Mail directory: /Users/jw/Library/Mail/V9/MailData Sat Mar 5 11:02:45 EST 2022 ...................................... usps -> imap://jdw.js13%40gmail.com/USPS bankofamerica.com -> imap://johnwiggins%40mac.com/bankofamerica.com Tablet -> imap://jdw.js13%40gmail.com/Tablet ...snip... VUDU Forums -> imap://johnwiggins%40mac.com/VUDU%20forums WhiteHouse -> imap://johnwiggins%40mac.com/WhiteHouse me -> imap://johnwiggins%40mac.com/family/me DELETE MSG -> Bank of America -> imap://johnwiggins%40mac.com/Bank%20of%20America%20Alert Junk_ -> Junk ...................................... 303 Rules in syncedRules.plist (/Users/jw/Library/Mail/V9/MailData) Sat Mar 5 11:03:21 EST 2022 version: do.showMailRules,v 1.3 2022/03/05 12:29:14 jw Exp $ (END)

NOTE: I had to add extension txt in order to get the forum to upload the file so after you download, you should:
mv do.showMailRules.txt do.showMailRules
Thank you very much!

jdw13

macrumors regular

Original poster

Oct 2, 2015

Boston, Maine, Chile

Thank you very much!
I just did a test download and see you need do the chmod command I just added to my entry.

Artiste212

macrumors member

Aug 26, 2012

Sure, but keep in mind it has very limited functionality to do just what I need.
It is an 'old-school' sh shell script and assumes that your Rules syncedRules and UnsyncedRules plist files are in the default location.
So if your data are in another location you need to change the line
inDir=~/Library/Mail/V9/MailData
The usage is very simple from the CLI. If you provide an arg, it will parse Unsynced Rules, otherwise your user-defined.
YMMV, so user beware. At least it should do no harm as it is read-only.
Just download and put in your execution path or call directly from Terminal or your favorite shell program.
Output goes to your screen. Example directing output to file:
$ do.showMailRules > MailRules.txt $ less MailRules.txt reading from Mail directory: /Users/jw/Library/Mail/V9/MailData Sat Mar 5 11:02:45 EST 2022 ...................................... usps -> imap://jdw.js13%40gmail.com/USPS bankofamerica.com -> imap://johnwiggins%40mac.com/bankofamerica.com Tablet -> imap://jdw.js13%40gmail.com/Tablet ...snip... VUDU Forums -> imap://johnwiggins%40mac.com/VUDU%20forums WhiteHouse -> imap://johnwiggins%40mac.com/WhiteHouse me -> imap://johnwiggins%40mac.com/family/me DELETE MSG -> Bank of America -> imap://johnwiggins%40mac.com/Bank%20of%20America%20Alert Junk_ -> Junk ...................................... 303 Rules in syncedRules.plist (/Users/jw/Library/Mail/V9/MailData) Sat Mar 5 11:03:21 EST 2022 version: do.showMailRules,v 1.3 2022/03/05 12:29:14 jw Exp $ (END)

NOTE: I had to add extension txt in order to get the forum to upload the file so after you download, you should:
mv do.showMailRules.txt do.showMailRules

P.S. If the file is not executable, you will need to

$ chmod 755 do.showMailRules
or similar command from your shell.
I tried it, but I'm getting this reply: zsh: permission denied: /Users/bruce/do.showMailRules.
Terminal has full disk permissions and I have read/write on the file do.showMailRules.
I have read/write permissions for Librar and all the subfolders and files down to the MailData folder. All files are in their original locations.
Perhaps my lesser experience in terminal is causing me to miss something?

jdw13

macrumors regular

Original poster

Oct 2, 2015

Boston, Maine, Chile

I tried it, but I'm getting this reply: zsh: permission denied: /Users/bruce/do.showMailRules.
Terminal has full disk permissions and I have read/write on the file do.showMailRules.
I have read/write permissions for Librar and all the subfolders and files down to the MailData folder. All files are in their original locations.
Perhaps my lesser experience in terminal is causing me to miss something?
Have you done
chmod 755 /Users/bruce/do.showMailRules
I added this to my post, it occurred to me in the shower. After that you should be able to execute with command
/Users/bruce/do.showMailRules

Artiste212

macrumors member

Aug 26, 2012

I hadn't done that, but I did, and it seemed to run properly.

Unfortunately, I'm getting the same error message

Artiste212

macrumors member

Aug 26, 2012

Have you done
chmod 755 /Users/bruce/do.showMailRules
I added this to my post, it occurred to me in the shower. After that you should be able to execute with command
/Users/bruce/do.showMailRules
I wonder if you have added and new commands to your terminal that allow you to do this but not me?

adrianlondon

macrumors 68040

Nov 28, 2013

3,447

4,101

Switzerland

If you just wanted the names, then a simple applescript would do the job.

tell application "Mail" to get name of rules

There may be ways to get the content of each rule too, but that's beyong my Mail scripting abilities/interest.

Reactions: Artiste212

jdw13

macrumors regular

Original poster

Oct 2, 2015

Boston, Maine, Chile

I wonder if you have added and new commands to your terminal that allow you to do this but not me?
Perhaps it is the file ownership. The chmod command I gave makes the file executable by the owner. Please let me know what happens if you make it executable by everyone:
chmod 777 /Users/bruce/do.showMailRules
and the command should run without any errors. If you don't have permission, try
sudo chmod 777 /Users/bruce/do.showMailRules
and
sudo /Users/bruce/do.showMailRules
which will prompt for your login password.
The only other thing that comes to mind is that I am an Admin user and Apple may have restricted shell script execution for normal users. That does not seem to be the case on Monterey 12.2.1 on my M1 Mac mini as I just logged in as Guest and was able to run the shell script after doing the chmod. The file should be owned by you. The command
ls -l /Users/bruce/do.showMailRules
should show protections "-rwxrwxrwx" and owner "bruce" and you do not need to be in group staff as the chmod command should make that irrevelant. If the file is not owned by bruce you can simply copy it to another file.
-rwxrwxrwx 1 bruce staff 2320 Mar 5 12:13 do.showMailRules.txt ^^^^^^^^^ ^^^^^
I like MacOS because it is just UNIX underneath but UNIX is not for everyone. Hope this gets you going....

Artiste212

macrumors member

Aug 26, 2012

Have you done
chmod 755 /Users/bruce/do.showMailRules
I added this to my post, it occurred to me in the shower. After that you should be able to execute with command
/Users/bruce/do.showMailRules
So I redownloaded the file, ran the chmod 755 command again, and this time it worked. No idea what went wrong before, but very happy to have this info. Thanks!

jdw13

macrumors regular

Original poster

Oct 2, 2015

Boston, Maine, Chile

So I redownloaded the file, ran the chmod 755 command again, and this time it worked. No idea what went wrong before, but very happy to have this info. Thanks!​
IMPORTANT NOTE IF YOU WANT TO USE do.showMailRules shell script on Monterey:
I did not see this, as I was writing and using the shell script within XQuartz.
You may see the following error if you try running script using Terminal, iTerm2 or other MacOS program.
If you can execute the script and get the following error:
do.showMailRules reading from Mail directory: /Users/<YourUserName>/Library/Mail/V9/MailData Sun Mar 6 08:55:49 EST 2022 <Path>/do.showMailRules: line 85: /Users/<YourUserName>/Library/Mail/V9/MailData/SyncedRules.plist: Operation not permitted ...snip...
If so you need to configure your program to have full disk access to read the plist files:
System Preferences :​
Security & Privacy :​
Full Disk Access :​
add Terminal or whatever program you are using to provide shell in which to run the script.​

Reactions: Artiste212


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK