Created
          February 21, 2024 07:46 
        
      - 
      
- 
        Save VimalMollyn/6ea17a5257cca11a7731ae17cd38c42b to your computer and use it in GitHub Desktop. 
    Auto Pause and Resume Dropbox sync on MacOS with python
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import subprocess | |
| def run_apple_script(apple_script): | |
| result = subprocess.run(['osascript', '-e', apple_script], capture_output=True, text=True) | |
| if result.returncode == 0: | |
| return result.stdout | |
| else: | |
| raise Exception(result.stderr) | |
| # Example usage | |
| script = '''tell application "System Events" | |
| -- Pause syncing | |
| click menu bar item 1 of menu bar 2 of application process "Dropbox" | |
| click menu item "Pause Syncing" of menu 1 of menu bar item 1 of menu bar 2 of application process "Dropbox" | |
| delay 2 | |
| -- Now re-enable syncing | |
| click menu bar item 1 of menu bar 2 of application process "Dropbox" | |
| click menu item "Resume Syncing" of menu 1 of menu bar item 1 of menu bar 2 of application process "Dropbox" | |
| end tell | |
| ''' | |
| output = run_apple_script(script) | |
| print(output) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Big thanks to @varenc for the original implementation. I just modified it to run in python :D. tjluoma/dropbox-pause-unpause#2 (comment)