Last active
July 24, 2024 09:28
-
-
Save gregneagle/6957826 to your computer and use it in GitHub Desktop.
Revisions
-
gregneagle revised this gist
Oct 28, 2013 . 1 changed file with 18 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,25 +1,31 @@ #!/usr/bin/python '''Uses Cocoa classes via PyObjC to set a random desktop picture on all screens. Tested on Mountain Lion and Mavericks. See: https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWorkspace_Class/Reference/Reference.html https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSScreen_Class/Reference/Reference.html ''' import glob import random from AppKit import NSWorkspace, NSScreen from Foundation import NSURL pictures_glob = glob.glob("/Library/Desktop Pictures/*.jpg") picture_path = random.choice(pictures_glob) # generate a fileURL for the desktop picture file_url = NSURL.fileURLWithPath_(picture_path) # make image options dictionary # we just make an empty one because the defaults are fine options = {} # get shared workspace ws = NSWorkspace.sharedWorkspace() -
gregneagle revised this gist
Oct 14, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,5 +27,5 @@ # iterate over all screens for screen in NSScreen.screens(): # tell the workspace to set the desktop picture (result, error) = ws.setDesktopImageURL_forScreen_options_error_( file_url, screen, options, None) -
gregneagle revised this gist
Oct 14, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,5 +27,5 @@ # iterate over all screens for screen in NSScreen.screens(): # tell the workspace to set the desktop picture error = ws.setDesktopImageURL_forScreen_options_error_( file_url, screen, options, None) -
gregneagle revised this gist
Oct 14, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,5 +27,5 @@ # iterate over all screens for screen in NSScreen.screens(): # tell the workspace to set the desktop picture (result, error) = ws.setDesktopImageURL_forScreen_options_error_( file_url, screen, options, None) -
gregneagle revised this gist
Oct 14, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ #!/usr/bin/python # https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWorkspace_Class/Reference/Reference.html # https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html # https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSScreen_Class/Reference/Reference.html from AppKit import NSWorkspace, NSScreen from AppKit import NSWorkspaceDesktopImageScalingKey -
gregneagle revised this gist
Oct 13, 2013 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,9 @@ #!/usr/bin/python # https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWorkspace_Class/Reference/Reference.html#//apple_ref/doc/uid/20000391-BCIEBDGB # https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html # https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSScreen_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSScreen from AppKit import NSWorkspace, NSScreen from AppKit import NSWorkspaceDesktopImageScalingKey from AppKit import NSImageScaleProportionallyUpOrDown -
gregneagle created this gist
Oct 13, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #!/usr/bin/python from AppKit import NSWorkspace, NSScreen from AppKit import NSWorkspaceDesktopImageScalingKey from AppKit import NSImageScaleProportionallyUpOrDown from AppKit import NSWorkspaceDesktopImageAllowClippingKey from Foundation import NSURL picture_path = "/Library/Desktop Pictures/Beach.jpg" # generate a fileURL file_url = NSURL.fileURLWithPath_(picture_path) # make image options dictionary options = { NSWorkspaceDesktopImageScalingKey: NSImageScaleProportionallyUpOrDown, NSWorkspaceDesktopImageAllowClippingKey: True } # get shared workspace ws = NSWorkspace.sharedWorkspace() # iterate over all screens for screen in NSScreen.screens(): # tell the workspace to set the desktop picture error = ws.setDesktopImageURL_forScreen_options_error_( file_url, screen, options, None)