I’m relatively new to programming, but learn quick. What I’d like to do is create a small app that will poll the ~/library/preferences/com.apple.desktop.plist file to see what the currently set desktop picture’s name is (ImageFilePath attribute in the default section)
I then want to display that file name in a display dialog.
I think this close to the code that will return the value that I’m looking for:
tell application "System Events" to return the value of property list item ¬
"ImageFilePath" of property list file ((path of preferences folder) & "com.apple.desktop.plist")
However I get a “System Events got an error: NSReceiverEvaluationScriptError: 4” when I run it and the word “value” is highlighted.
First, how to I resolve the error above and second, how to I pass this into a variable so that I can then display the result?
I’ve got a built and running application. However (there’s always a “however”) it doesn’t quite work right. My problem (and I likely should have mentioned this earlier) is that my desktop picture rotates through random pictures that are in a folder. The whole reason that I wanted this app was so that I could see what the name of the current picture was as they’re all of places in Germany and the filenames are as such.
Here’s my code:
on clicked theObject
set DP to ""
set MyText to ""
tell application "Finder" to set DP to {name} of (desktop picture as alias)
set MyText to (DP as string)
set the contents of text field "textfield" of window "main" to MyText
end clicked
What I’ve noticed is that if you open up ~/library/preferences/com.apple.desktop.plist and then go into Root/Background/default the key that the above code is pulling from is ImageFilePath. This key is an apparent reference to the last picture that was explicitly selected as my desktop picture (before I turned on the rotating picture feature). The key that is accurate, and I can see change each time the desktop picture changes is Root/Background/default/LastName. Now, is there a way to grab this and drop it into my DP variable? I’m going to try to go back to the System Events app and use the plist functions there. Any ideas on that?
I just love when I’m the biggest poster to my own thread
I figured it out!
So I changed up my code a bit. Now it is:
on clicked theObject
tell application "System Events"
set DP to value of (property list item "LastName of
property list item "default" of property list item
"Background" of property list file
((path of preferences folder as Unicode text) &
"com.apple.desktop.plist"))
end tell
set the contents of text field "textfield" of window "main" to DP
end clicked
(BTW, there are soft returns at the end of the lines in the tell block above - Option-Return)