I am trying to make an application that changes the background every time the application is run. However, I run my current app and nothing happens. What I am I doing wrong? Here is what I have:
tell application "Finder"
set desktop picture to file "Users/Administrator/Desktop/3g-apple-iphone5.jpg"
end tell
P.S. I googled to see what I could find, and nothing I tried that was what I was looking for worked. So i need help! SO PLEASE HELP.
That used to be the case, but it’s not so clear-cut now. All the standard additions commands that list “file” as a parameter will, as of 10.6, accept a POSIX path (or even an HFS path). The same applies for commands in apps using Cocoa scripting. The Finder is not one of these, though.
The script appears to be correct, but it doesn’t work for me either. I had more success with this:
set p2dpf to (path to desktop as text) & "3g-apple-iphone5.jpg"
tell application "System Events"
tell current desktop
set picture rotation to 0 -- 0 = never.
set picture to file p2dpf
end tell
end tell
i have my pic in my pictures folder now, what do I have to change to set the pic to be the pic in my pics folder? If my pics title has spaces, do I need to replace it with underscores? Please help.
This seems to work in 10.6.6. There’s probably a more economical way to cover the possibilities than with four “sed” commands, but I don’t know it:
set p2dpf to (path to desktop as text) & "3g-apple-iphone5.jpg"
tell application "System Events"
tell current desktop
set picture rotation to 0 -- 0 = never.
set picture to file p2dpf
end tell
end tell
-- This shell script reads the Desktop picture preferences file ("com.apple.desktop.plist"),
-- replaces any of the other possible "Placement" settings with "SizeToFit",
-- writes the edited preferences back to the file,
-- and kills the Dock process so that it restarts with the new settings.
do shell script "a=$(defaults read com.apple.desktop | sed s/\"Placement = Crop;\"/\"Placement = SizeToFit;\"/g | sed s/\"Placement = FillScreen;\"/\"Placement = SizeToFit;\"/g | sed s/\"Placement = Centered;\"/\"Placement = SizeToFit;\"/g | sed s/\"Placement = Tiled;\"/\"Placement = SizeToFit;\"/g) ; defaults write com.apple.desktop \"$a\" ; killall Dock"
It does “Fit to Screen” (the option name displayed in System Preferences on English systems) on my machine, whatever the placement was before. Of course, if System Preferences is open while the script’s run, it won’t show any change until it’s quit and reopened.
Other than that, I’m not sure what to suggest, except perhaps trying a short delay between the System Events code and the shell script.