Created
April 22, 2020 04:51
-
-
Save hafta/8efc203d33fea574959152111343a554 to your computer and use it in GitHub Desktop.
Python script to print the path to the image used as the desktop background of the focussed screen
This file contains 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
#!/usr/bin/python | |
# This Source Code Form is subject to the terms of the Mozilla Public | |
# License, v. 2.0. If a copy of the MPL was not distributed with this | |
# file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
from AppKit import NSScreen, NSWorkspace | |
def main(): | |
focussedScreen = NSScreen.mainScreen() | |
if not focussedScreen: | |
raise RuntimeError("mainScreen error") | |
workspace = NSWorkspace.sharedWorkspace() | |
if not workspace: | |
raise RuntimeError("sharedWorkspace error") | |
imageURL = workspace.desktopImageURLForScreen_(focussedScreen) | |
if not imageURL: | |
raise RuntimeError("desktopImageURLForScreen returned invalid URL") | |
if not imageURL.isFileURL(): | |
raise RuntimeError("desktop image URL is not a file URL") | |
print(imageURL.path()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment