I have been playing with Python recently.
Here is a little script to change a mac’s desktop wallpaper to the file specified as the first argument of the script:
import subprocess,sys,os # Raw apple script Script = """/usr/bin/osascript<<END tell application "Finder" set desktop picture to POSIX file "%s" end tell END""" # get the file name which is the first argument passed to this script filename = sys.argv[1] # run the apple script inserting the filename subprocess.Popen(Script%filename,shell=True)
Or using the nifty appscript module for python:
import sys
from appscript import app, mactypes
# get the file name which is the first argument passed to this script
fileName = sys.argv[1]
# use the appscript module to change the desktop wallpaper
app('Finder').desktop_picture.set(mactypes.File(fileName))
The more I use Python the more I like it. I used to think Python was at a similar level to C# in terms of how high a level a programming language it is. After using Python for a bit I now realise that Python is a higher level programming language than C#. Out of the languages I use reguarally it would seem that Python is the highest level language followed by C# then C++ and finally C.
Post a Comment