Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

A friend asked me how to run this tool in the background to refresh every 45 minutes. this is a launchagent working as of macOS Sonoma 14.6.1.

A LaunchAgent for a single account: (or one per account)

  1. Place imapsync in /usr/local/bin/oauth2_imap (this is required to run an executable without disabling sip).
  2. Run the perl script once to generate the token file token/, or place the file there if you already have it.
  3. Create a an empty file in ~/Library/LaunchAgents/ named com.imapsync.gmail.plist.
  4. Paste the following inside and change according to the email account and token file location:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <false/>
 <key>Label</key>
 <string>com.imapsync.gmail</string>
 <key>LaunchOnlyOnce</key>
 <false/>
<key>WorkingDirectory</key>
<string>/usr/local/bin/oauth2_imap</string>
 <key>ProgramArguments</key>
 <array>
  <string>/usr/local/bin/oauth2_imap/oauth2_imap</string>
   <string>--token_file</string>
   <string>/usr/local/bin/oauth2_imap/tokens/oauth2_tokens_USER@MAILPROVIDER.com.txt</string>
   <string>USER@MAILPROVIDER.com</string>
   <string>--provider</string>
   <string>MAILPROVIDER</string>
 </array>
 <key>StandardErrorPath</key>
 <string>/tmp/imapsync.gmail.log</string>
 <key>StandardOutPath</key>
 <string>/tmp/imapsync.gmail-stdout.log</string>
  <key>StartInterval</key>
  <integer>2700</integer>
</dict>
</plist>
  1. In Terminal type this command launchctl load ~/Library/LaunchAgents/com.imapsync.gmail.plist then launchctl start ~/Library/LaunchAgents/com.imapsync.gmail.plist
  2. That's it, you're done.

For Multiple Account (using a shellscript):

same steps 1-3

  1. Paste the following inside and change according to the script name and location:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>KeepAlive</key>
 <false/>
 <key>Label</key>
 <string>com.imapsync.gmail</string>
 <key>LaunchOnlyOnce</key>
 <false/>
<key>WorkingDirectory</key>
<string>/usr/local/bin/oauth2_imap</string>
 <key>ProgramArguments</key>
 <array>
    <string>/bin/bash</string>
    <string>/usr/local/bin/oauth2_imap/oauth2_gmail.sh</string>
 </array>
 <key>StandardErrorPath</key>
 <string>/tmp/imapsync.gmail.log</string>
 <key>StandardOutPath</key>
 <string>/tmp/imapsync.gmail-stdout.log</string>
  <key>StartInterval</key>
  <integer>2700</integer>
</dict>
</plist>
  1. Create an empty file named oauth2_gmail.sh inside /usr/local/bin/oauth2_imap.
  2. Paste the following inside the oauth2_gmail.sh and change the field according to your accounts:
#!/usr/bin/env bash

./oauth2_imap --token_file   tokens/oauth2_tokens_USER@MAILPROVIDER.com   USER@MAILPROVIDER.com
  1. In Terminal type this command launchctl load ~/Library/LaunchAgents/com.imapsync.gmail.plist then launchctl start ~/Library/LaunchAgents/com.imapsync.gmail.plist
  2. That's it, you're done.
You must be logged in to vote

Replies: 1 comment

Comment options

This is all Greek to me but thanks Amr!

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.