How to change desktop background in AppleScript in 10.7?

I'm just now upgrading from 10.6 to 10.7, and I'm having trouble with a script that I wrote that worked fine under 10.6.  In part, it executes the following command:
     osascript -e "tell application \"Finder\" to set destop picture to POSIX file \"<path>\""
to change the desktop background image to one of two different files based on other conditions.
In 10.7, this command completes with no error code, but it only changes the background of one of my four desktops.  Is there a way to programmatically change the background image of all of my desktops simultaneously?  Failing that, is there a way to a) find out how many desktops I have and b) loop through them, setting each of their backgrounds in turn?
I did search the web and found the following suggestion:
     osascript -e "tell application \"System Events\" to set picture of every desktop to \"<path>\""
Unfortunately, that also changes only the current desktop's picture.
The larger script is in Perl, so I'd prefer a technology that works well with that language, but if I have to change to a different scripting language, that's not the end of the world.
Thanks much for any suggestions!
Richard

Actually, “repeat with k from 18 to (18 + N - 1)” was not a good idea, since it works only with N < 5, as I discovered after posting the script.
So here's an improved version of the previous script that should work with any number of desktops:
set theFile to POSIX file "/Library/Desktop Pictures/Isles.jpg" -- just an example
-- Find out how many desktops you have:
tell application "System Preferences"
    reveal anchor "shortcutsTab" of pane id "com.apple.preference.keyboard"
    tell application "System Events" to tell window "Keyboard" of process "System Preferences"
        set N to count (UI elements of rows of outline 1 of scroll area 2 of splitter group 1 of tab group 1 whose name begins with "Switch to Desktop")
    end tell
    quit
end tell
-- Loop through the desktops, setting each of their backgrounds in turn:
tell application "System Events" to key code 18 using {control down} -- Desktop 1
tell application "Finder" to set desktop picture to theFile
repeat (N - 1) times
    delay 1
    tell application "System Events" to key code 124 using {control down} -- ⌘→
    delay 1
    tell application "Finder" to set desktop picture to theFile
end repeat

Similar Messages

  • How to change desktop background at specific time of day

    Pretty much all in the title, although i guess i should add that it would be good if I could have the background change on all desktops at once. Basically I'd just like to have daytime themed images in the day and nighttime themed ones at, you guessed it, night. Thanks in advance!

    A hacky way of doing it would be:
    Make 12 copies of the daytime image, but give them different names
    Make 12 copies of the nightime image, but give them different names
    Put the images in a folder.
    Opern the folder in System Preferences ----> Desktop
    Select the images. Make sure it is set to change the pictures every hour.
    But the question is ----> Will this work if you switch your mac off ? XD
    Probably not.
    Perhaps you should look for an app in the app store that can do this.

  • HT2478 how do you make the setting to change desktop background every time you shut down your mac

    how to make setting to change desktop background every time you close your mac
    because i want to make it if anybody tries to change my dekstop picture i want it to go backto set desktop picture

    Don't let other people access your Mac in admin mode - they might change something a lot more important than the Desktop picture.
    However you can use Automator: create an Application in it, and select 'Set the Desktop Picture' from the Library. Choose the picture you want. Save the application, then go to System Preferences>Accounts>Login Items and select the Automator application you just created. This will then run at startup and set your chosen picture.

  • How to change the background color of a desktop??

    any ideas how to change the background color of a desktop?? Now the default color is blue. I couldn't fine the API in JDesktopPane on doing that..
    JDesktopPane desktop = new JDesktopPane(); //(textArea);

    Try the method setBackground. For me it's work.

  • Change Desktop Background - Stretch Picture

    I noted a strange thing when i right click and select Change Desktop Background, i once noted the option of whether to Stretch the picture. But now it is gone.
    Does anyone know how do i enable it?

    The option is only offered when it is actually needed, most likely your images don't need stretching.
    Mario

  • How to change the background color of a single row

    Hi OTN,
    I am using JDeveloper 11.1.1.2 with ADF faces in view layer.My issue is How to change the background color of a single row in af:table ?.

    How to highlight ADF table row based on column value?
    Found by searching

  • Wallpaper not showing up in "Change Desktop Background" window

    I just noticed an odd issue today on my Mac Pro. When browsing the built-in wallpaper folders (Nature, Plants, etc) in the Change Desktop Background window they are empty. My "Pictures Folder" one shows all the images correctly as well as browsing the ones from iPhoto. (I also have Aperture 2.1.2 installed but no projects yet so that part is empty.)
    I performed a permissions repair, checked that the actual files were there in /Library and removed the com.apple.desktop.plist pref's file. After doing that all the pictures showed up again UNTIL I browsed around the picture folders in the Change Desktop Background window then they stopped showing again.
    Could something in my Pictures Folder be causing the issue? Any ideas?
    Thanks,
    -Jim

    Thanks for clarifying. I don't do right or left click, but occasionally do CONTROL-click and doing that brings up the contextual menu item "change desktop background" which leads to the Desktop prefPane. Now, why you're having issues, I have no idea. However, I suggest creating a new admin user account, logging into it, and seeing if changing the desktop picture works there.

  • "Change desktop background" instantly hides when opened

    I have a rather strange issue that's a nuisance. When I right click on the desktop and select "Change Desktop Background," the system preferences pane opens, but automatically is hidden (similar to if you press cmd+H). I have to click the icon to restore the window.
    This does NOT occur if I first open System Preferences and then select "Desktop & Screen Saver," or if I open "DesktopScreenEffectsPref.prefpane" from quicksilver.
    I have tried deleting com.apple.desktop.plist and restarting, but this did not solve my problem. I think I may have experienced this problem in Lion as well, but I currently experience it on Mountain Lion.
    Any help is greatly appreciated.

    This same thing happens to me, and while not the end of the world, it is defintely annoying.  Have you figured it out?  Thanks!

  • Change Desktop Background Broken 10.8

    When I "2 finger (right click)" click on the desktop and select "Change Desktop Background", System Preferences comes up and I can change my background.   I then close System Preferences and try it again and System Prefrences doesnt open.  It will work the 1st time after a reboot, but not work anytime after.
    Is anyone else having this issue?
    Is there anyway to see what that command is doing on the context menu?  "Change Desktop Background"

    I'm having a similar problem after installing Mountain Lion on a new MBP Retina. Sorry I didn't see your post before I duplicated it (https://discussions.apple.com/thread/4217330?tstart=30).

  • How to change entire background to black in Elements 11?

    I have a photo of a red rose - I'm trying to change the entire background to black - how?

    Thanks so much for your quick reply - I've printed off your instructions, I'll give it a shot later today.  Elem 11 is quite a step up from Elem 5 for me - I think I'm in for somewhat of a learning curve.  Thanks again!! Glen...
      From: hatstead
      Sent: Friday, August 16, 2013 12:56 PM
      To: Ermineglen
      Subject: How to change entire background to black in Elements 11?
            Re: How to change entire background to black in Elements 11?
            created by hatstead in Photoshop Elements - View the full discussion

  • Issue with desktop Opt/Click (right click) & 'Change Desktop Background'

    I have an issue with the opt/click in the desktop in ML 10.8.2. The 'Change Desktop Background' using opt/click (right click) works after reboot, but fails to open (work correctly) thereafter. The 'System Preferences' icon bounces in the dock but nothing else happens, I have either click on the SP icon or re-opt/click (R click) again to get it working. All else seems to be in order but not this. I have tried this with 2 complete full installs & still doesn't work correctly (same issue. I have reported it to Apple, but I was wondering if anyone else experiencing this problem?

    So, here's what I've learned so far.
    Fresh reboot.  Works fine.  Close and try again, doesn't work.  This you already know.
    Here's what I tried to see if it makes a difference:
    I removed:
    ~/Library/Caches
    ~/Library/Preferences/com.apple.finder.*, com.apple.systempreferences.* and com.apple.desktop.*
    That didn't help.
    I tried it in safe mode.  Same issue.
    Here's something interesting I noticed.  If you open terminal and killall Finder, that refreshes it and makes it work again... for 1 try.
    This does, in fact, seem like a bug.
    For reference, I'm currently on a mid 2012 macbook pro.  Running fully updated on mt lion.

  • Changing desktop background issue12

    hi, I have an issue with my macbook pro retina display 13" running mountaion lion os.
    I was trying to change my desktop background, so I right-clicked my mouse and choose 'change desktop background option'. The first time I did this, nothing happened (however i noticed that the 'system preferences' icon on my dock was bouncing after I did that). When I tried to do the same thing again, it worked.  I did this several times and I noticed it will only work on the second time. fyi I was not having this issue till today. Anyone else facing the same issue? Do I need to format my laptop or re-install my ios to remove this bug?
    sorry for my bad English. Thanks!

    hi! thanks for the reply.
    I tried to follow the instructions, but I don't understand with the last instruction which says "Restart the computer and open System Preferences (or problem program) and reset all your preferences again"
    I went to restart my computer (after deleting the com.apple.system...), and it doesnt solve the issue. However, I noticed that deleting the com.apple.system the "change desktop background" will work once. but if i close and do it the again, it wont work (same thing if i restart my laptop). I know i am just being anal about this small issue lol, but i noticed some other users experience the same thing as well as me.
    https://discussions.apple.com/message/22567888#22567888
    or
    https://discussions.apple.com/thread/4146106
    thanks for the reply =) I will try to ask my friend whether he is having the same issue as me.

  • How to change color background

    Hello Everybody,
    So i downloaded a tempelate off the internet
    and was wondering how i would change the background.
    I can not figure it out:
    html code;
    <strong></strong><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <!--
    Design by Free CSS Templates
    http://www.freecsstemplates.org
    Released for free under a Creative Commons Attribution 2.5 License
    Name       : Distillate 
    Description: A two-column, fixed-width design with dark color scheme.
    Version    : 1.0
    Released   : 20100427
    -->
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Distillate   by Free CSS Templates</title>
    <link href="file:///C|/Users/Sami/Desktop/style.css" rel="stylesheet" type="text/css" media="screen" />
    <script type="text/javascript" src="file:///C|/Users/Sami/Desktop/jquery/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="file:///C|/Users/Sami/Desktop/jquery/jquery.gallerax-0.2.js"></script>
    </head>
    <body>
        <div id="header-wrapper">
            <div id="header">
                <div id="logo">
                    <h1><a href="#">Distillate</a></h1>
                    <p> design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a></p>
                </div>
            </div>
        </div>
        <div id="page">
            <div id="page-bgtop">
                <div id="page-bgbtm">
                    <div id="content">
                      <div>
                        <div id="gallery">
                          <div id="gallery-background"><img src="<?php bloginfo('template_url'); ?>/images/img06.png" alt="" width="600" height="340" class="output" /></div>
                          <div id="gallery-bgthumb">
                            <ul class="thumbnails">
                              <li><img src="file:///C|/Users/Sami/Desktop/Sample Website/Sunset.jpg"" alt="" width="128" height="88" /></li>
                              <li><img src="file:///C|/Users/Sami/Desktop/Sample Website/sunset 280.jpg"" alt="" width="100" height="75" /></li>
                              <li><img src="file:///C|/Users/Sami/Desktop/images/7.jpg" title="Chinese Bell ; A large bell inscribed with Chinese characters." alt="" width="100" height="75" /></li>
                              <li><img src="file:///C|/Users/Sami/Desktop/images/8.jpg" title="Ladybird ; A close up shot of a ladybird making its way across a leaf." alt="" width="100" height="75" /></li>
                            </ul>
                            <br class="clear" />
                          </div>
                        </div>
                        <script type="text/javascript">
                            $('#gallery').gallerax({
                                outputSelector:         '.output',                    // Output selector
                                thumbnailsSelector:        '.thumbnails li img',        // Thumbnails selector
                                fade:                     'fast',                        // Transition speed (fast)
                                navNextSelector:        '.nav li a.navNext',        // 'Next' selector
                                navPreviousSelector:    '.nav li a.navPrevious'        // 'Previous' selector
                        </script>
                        <!-- end -->
                      </div>
                      <div class="post">
                        <h2 class="title"><a href="#">Welcome to Distillate </a></h2>
                        <p class="meta">Posted by <a href="#">Someone</a> April 22, 2010</p>
                        <div style="clear: both;"> </div>
                        <div class="entry">
                          <p>This is <strong>Distillate, </strong>a free, fully standards-compliant CSS template designed by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>, released for free under the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution</a> license.The slideshow uses photos from <a href="http://www.pdphoto.org">PDPhoto.org</a> and is powered by Gallerax (a jQuery plugin by <a href="http://www.nodethirtythree.com/">NodeThirtyThree</a>). You're free to use this template for anything as long as you link back to our site. Enjoy :)</p>
                          <p>Sed lacus. Donec lectus. Nullam pretium nibh ut turpis. Nam bibendum. In nulla tortor, elementum ipsum. Proin imperdiet est. Phasellus dapibus semper urna. Pellentesque ornare, orci in felis. Donec ut ante. In id eros. Suspendisse lacus turpis, cursus egestas at sem.</p>
                          <p class="links"><a href="#">Read More</a>    |    <a href="#">Comments</a></p>
                        </div>
                      </div>
                      <div class="post">
                        <h2 class="title"><a href="#">Lorem ipsum sed aliquam</a></h2>
                        <p class="meta">Posted by <a href="#">Someone</a> April 10, 2010</p>
                        <div style="clear: both;"> </div>
                        <div class="entry">
                          <p>Sed lacus. Donec lectus. Nullam pretium nibh ut turpis. Nam bibendum. In nulla tortor, elementum vel, tempor at, varius non, purus. Mauris vitae nisl nec metus placerat consectetuer. Donec ipsum. Proin imperdiet est. Phasellus <a href="#">dapibus semper urna</a>. Pellentesque ornare, orci in consectetuer hendrerit, urna elit eleifend nunc, ut consectetuer nisl felis ac diam. Etiam non felis. Donec ut ante. In id eros. Suspendisse lacus turpis, cursus egestas at sem.  Mauris quam enim, molestie in, rhoncus ut, lobortis a, est.</p>
                          <p class="links"><a href="#">Read More</a>    |    <a href="#">Comments</a></p>
                        </div>
                      </div>
    <div style="clear: both;"> </div>
                    </div>
                    <h3><!-- end #content -->
                  </h3>
                    <div id="sidebar">
                        <ul>
                            <li>
                                <div id="search" >
                                    <form method="get" action="#">
                                        <div>
                                            <input type="text" name="s" id="search-text" value="" />
                                            <input type="submit" id="search-submit" value="GO" />
                                        </div>
                                    </form>
                                </div>
                                <div style="clear: both;"> </div>
                            </li>
                            <li>
                                <h2>Aliquam tempus</h2>
                                <p>Mauris vitae nisl nec metus placerat perdiet est. Phasellus dapibus semper consectetuer hendrerit.</p>
                            </li>
                            <li>
                                <h2>Categories</h2>
                                <ul>
                                    <li><a href="index.html">Home</a></li>
                                    <li><a href="about.html">About Us</a></li>
                                    <li><a href="services.html">Services</a></li>
                                    <li><a href="location.html">Office Location</a></li>
                                    <li><a href="tour.html">Office Tour</a></li>
                                    <li><a href="contact.html">Contact Us</a></li>
                                </ul>
                            </li>
                            <li>
                                <h2>Blogroll</h2>
                                <ul>
                                    <li><a href="#">Aliquam libero</a></li>
                                    <li><a href="#">Consectetuer adipiscing elit</a></li>
                                    <li><a href="#">Metus aliquam pellentesque</a></li>
                                    <li><a href="#">Suspendisse iaculis mauris</a></li>
                                    <li><a href="#">Urnanet non molestie semper</a></li>
                                    <li><a href="#">Proin gravida orci porttitor</a></li>
                                </ul>
                            </li>
                            <li>
                                <h2>Archives</h2>
                                <ul>
                                    <li><a href="#">Aliquam libero</a></li>
                                    <li><a href="#">Consectetuer adipiscing elit</a></li>
                                    <li><a href="#">Metus aliquam pellentesque</a></li>
                                    <li><a href="#">Suspendisse iaculis mauris</a></li>
                                    <li><a href="#">Urnanet non molestie semper</a></li>
                                    <li><a href="#">Proin gravida orci porttitor</a></li>
                                    <li><a href="#">Suspendisse iaculis mauris</a></li>
                                    <li><a href="#">Urnanet non molestie semper</a></li>
                                    <li><a href="#">Suspendisse iaculis mauris</a></li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                    <!-- end #sidebar -->
                    <div style="clear: both;"> </div>
                </div>
            </div>
        </div>
        <!-- end #page -->
    <div id="footer">
        <p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
    </div>
    <!-- end #footer -->
    </body>
    </html>

    how do I do it?
    Press F1.  Search for "define site".  Read the comprehensive instructions there.

  • Cannot Change Desktop Background in Windows 8 Installed Via Bootcamp

    I've been running parelells, but decided today to just go the boot camp route and everything went through fine EXCEPT I cannot change the wall paper on the windows 8 desktop?
    I select the new image in desktop background in personalization click save changes and the background stays the same...?
    I don't get it.
    And by the way, I am NOT new to windows or mac, been using both for a long time and was a systems administrator and bench for years, this is NOT a novice "how to" question...It's just not working?
    Anyone else seen this before?

    are you using an activated version of win 8? you cant personalise win desktop otherwise.

  • Image distortion via Change Desktop Background?

    A couple of months ago, I was searching through my iPhoto gallery looking for a picture to set as my "new" desktop background. As I changed from one background to another, the over-all display from my MBPR (MacBook Pro Retina) exhibited distortion. I do not know how to explain the effect any further, but I went to my nearest Apple Store yesterday, and I was told by a genius that it may simply be a bug. He also ran several tests on my MBPR and found nothing out of the ordinary.. Has anyone else experienced this phenomenon?

    Hello
    What kind of image file you want to set as background? As far as I know not all picture formats work as desktop background.
    You should try it with a JPEG picture. Such pictures always work properly.
    Otherwise you must ask on a Microsoft forum. Here we can talk about Toshiba notebooks.

Maybe you are looking for