How can I programmatically change the background in Mac OS X?

后端 未结 10 1933
轮回少年
轮回少年 2020-11-28 03:30

How would I go about programmatically changing the desktop background in Mac OS X? I\'d like to use python, but I\'m interested in any way possible. Could I hook up to Ter

10条回答
  •  执笔经年
    2020-11-28 03:59

    I had this same question, except that I wanted to change the wallpaper on all attached monitors. Here's a Python script using appscript (mentioned above; sudo easy_install appscript) which does just that.

    #!/usr/bin/python
    
    from appscript import *
    import argparse
    
    def __main__():
      parser = argparse.ArgumentParser(description='Set desktop wallpaper.')
      parser.add_argument('file', type=file, help='File to use as wallpaper.')
      args = parser.parse_args()
      f = args.file
      se = app('System Events')
      desktops = se.desktops.display_name.get()
      for d in desktops:
        desk = se.desktops[its.display_name == d]
        desk.picture.set(mactypes.File(f.name))
    
    
    __main__()
    

提交回复
热议问题