macosapplescriptosx-mountain-lion

Using Applescript to Change desktop icon size


I am currently using applescript to setup various parameters of the desktops at my university. So far my script successfully changes the desktop background and the dock size.

The problem at hand is when I run the script, majority of the time, the icons on the desktop never change.

Here is the script I wrote to alter the desktop icon's size and grid spacing:

tell application "System Events"
    set finderPrefsFile to property list file "~/Library/Preferences/com.apple.Finder.plist"
    tell finderPrefsFile
        tell property list item "DesktopViewSettings"
            tell property list item "IconViewSettings"
                set value of property list item "gridSpacing" to "100"
                set value of property list item "iconSize" to "32"
                set value of property list item "arrangeBy" to "none"
            end tell
        end tell
    end tell
end tell
#Restart Finder for changes to take effect.
do shell script "killall Finder"

How should I go about altering the script to make it work all the time (I would like to eventually share this script with some of my classmates).

P.s. Here is the full script


Solution

  • I didn't get your script work reliable. I played around with timeouts but didn't get the Finder to refresh using the new settings. But I found to set some view options directly using vanilla AppleScript:

    tell application "Finder"
        activate
        set iconViewOptions to desktop's window's icon view options
        tell iconViewOptions
            set arrangement to not arranged
            set icon size to 32
            set shows item info to false
            set shows icon preview to false
        end tell
        quit
    end tell
    delay 1
    tell application "Finder" to activate
    

    The AppleScript quit-handler works more reliable then do shell script "killall Finder", maybe the killall is too hard...

    The delay 1 does the magic to give the Finder the time to breath before get up again and using it the Script works each time...

    But one thing is AFAIK not possible in Finder scripting: Setting the grid space :-/

    Greetings, Michael / Hamburg