Can I lock Desktop icons? Dock?

Discussion in 'Mac Basics and Help' started by c23roo, Sep 21, 2010.

  1. c23roo macrumors regular

    Joined:
    May 29, 2004
    #1
    Does anyone know if there's a way to lock my desktop icons (so my curious kids don't mistakenly - or not so mistakenly - move stuff around or into trash). My desktop is kept fairly simple (icons for the various HDs and folders for homework). We've also had the issue of items going *poof* from the dock - which is an easily fixable issue - but a little bit of a nuisance to have to retrieve from time to time.
    Thanks!
     
  2. spinnerlys Guest

    spinnerlys

    Joined:
    Sep 7, 2008
    Location:
    forlod bygningen
    #2
    What about a separate ACCOUNT for your children with Parental Controls enabled?
     
  3. Jolly Jimmy macrumors 65816

    Jolly Jimmy

    Joined:
    Dec 13, 2007
    #3
    I use this little script I made to lock/unlock the dock's icons and size.

    Code:
    set LockedContents to do shell script "defaults read com.apple.dock contents-immutable"
    set LockedSize to do shell script "defaults read com.apple.Dock size-immutable"
    
    if LockedContents = "1" and LockedSize = "1" then
    	set ContentsLock to "defaults write com.apple.dock contents-immutable -bool false"
    	set SizeLock to "defaults write com.apple.Dock size-immutable -bool no"
    	display dialog "Press OK to unlock the dock"
    else
    	set ContentsLock to "defaults write com.apple.dock contents-immutable -bool true"
    	set SizeLock to "defaults write com.apple.Dock size-immutable -bool yes"
    	display dialog "Press OK to lock the dock"
    end if
    
    try
    	do shell script ContentsLock
    	do shell script SizeLock
    	delay 0.5
    	do shell script "KillAll Dock"
    end try
    Open it in Applescript Editor and save it as an application.
     
  4. c23roo thread starter macrumors regular

    Joined:
    May 29, 2004
    #4
    Thanks for the help!
    Note to self: must remember to try drinking in the morning again.

    Cheers!
     
  5. rdforbes macrumors newbie

    Joined:
    Sep 23, 2010
    #5
    Hi - I'm new to Applescripts, so forgive me if this is something obvious. I copy/pasted your script into the AppleScript Editor, but when I ran it I got an error on the first line:

    error "2010-09-23 23:52:26.489 defaults[6758:60f]
    The domain/default pair of (com.apple.dock, contents-immutable) does not exist" number 1

    Any ideas of what I did wrong?
    Thanks,
    Ron
     
  6. Jolly Jimmy macrumors 65816

    Jolly Jimmy

    Joined:
    Dec 13, 2007
    #6
    What version of OS X are you running? I've only tested this script on 10.6.
     
  7. AdeFowler macrumors 68020

    AdeFowler

    Joined:
    Aug 27, 2004
    Location:
    England
  8. Jolly Jimmy macrumors 65816

    Jolly Jimmy

    Joined:
    Dec 13, 2007
    #8
    Onyx is good but can only lock the contents and not the size.
     
  9. AdeFowler macrumors 68020

    AdeFowler

    Joined:
    Aug 27, 2004
    Location:
    England
    #9
    Fair comment but the OP was only frustrated by icons disappearing, not the dock resizing ;)
     
  10. rdforbes macrumors newbie

    Joined:
    Sep 23, 2010
    #10
    10.6.4. I just wish I knew more about AppleScript to be able to interpret the error message.
     

    Attached Files:

  11. Jolly Jimmy macrumors 65816

    Jolly Jimmy

    Joined:
    Dec 13, 2007
    #11
    I'm still learning applescript. Try this out :

    Code:
    try
    	set LockedContents to do shell script "defaults read com.apple.dock contents-immutable"
    on error
    	do shell script "defaults write com.apple.dock contents-immutable -bool false"
    	set LockedContents to do shell script "defaults read com.apple.dock contents-immutable"
    end try
    
    try
    	set LockedSize to do shell script "defaults read com.apple.Dock size-immutable"
    on error
    	do shell script "defaults write com.apple.Dock size-immutable -bool no"
    	set LockedSize to do shell script "defaults read com.apple.Dock size-immutable"
    end try
    
    if LockedContents = "1" and LockedSize = "1" then
    	set ContentsLock to "defaults write com.apple.dock contents-immutable -bool false"
    	set SizeLock to "defaults write com.apple.Dock size-immutable -bool no"
    	display dialog "Press OK to unlock the dock"
    else
    	set ContentsLock to "defaults write com.apple.dock contents-immutable -bool true"
    	set SizeLock to "defaults write com.apple.Dock size-immutable -bool yes"
    	display dialog "Press OK to lock the dock"
    end if
    
    try
    	do shell script ContentsLock
    	do shell script SizeLock
    	delay 0.5
    	do shell script "KillAll Dock"
    end try
     
  12. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #12
    That script could be shortened and user interaction can be removed. And if you are going to prompt the user for action, might as well give the choice in case (for some reason) they don't know the current status of the dock.

    Automated, based on the current value
    Code:
    -- Get the current values
    try
    	set lockedContents to do shell script "defaults read com.apple.dock contents-immutable"
    	set lockedSize to do shell script "defaults read com.apple.Dock size-immutable"
    on error
    	-- Couldn't grab current status, let's assume a lock
    	set toggleValue to true
    end try
    
    -- Set the value based on the current
    if lockedContents = "1" and lockedSize = "1" then
    	set toggleValue to false
    else
    	set toggleValue to true
    end if
    
    -- Lock or Unlock the Dock
    toggleDockLock(toggleValue)
    
    ------------------------------------------
    -- Functions --
    ------------------------------------------
    to toggleDockLock(toggleValue)
    	set contentsLock to "defaults write com.apple.dock contents-immutable -bool " & toggleValue
    	set sizeLock to "defaults write com.apple.Dock size-immutable -bool " & toggleValue
    	
    	-- Perform the requested action
            try
    	     do shell script contentsLock
    	     do shell script sizeLock
    	     do shell script "killall Dock"
           end try
    end toggleDockLock
    
    Let the user decide
    Code:
    -- Ask the user if they want to Lock or Unlock the Dock
    set userPrompt to display dialog "Do you want to Lock or Unlock the Dock?" buttons {"Lock", "Unlock", "Cancel"} default button "Lock"
    set userAction to button returned of userPrompt
    
    -- Turn the user request into a useable value
    if userAction is "Lock" then
    	set toggleValue to true
    else if userAction is "Unlock" then
    	set toggleValue to false
    end if
    
    -- Perform the requested action
    toggleDockLock(toggleValue)
    
    ------------------------------------------
    -- Functions --
    ------------------------------------------
    to toggleDockLock(toggleValue)
    	set contentsLock to "defaults write com.apple.dock contents-immutable -bool " & toggleValue
    	set sizeLock to "defaults write com.apple.Dock size-immutable -bool " & toggleValue
    	
    	-- Perform the requested action
            try
    	     do shell script contentsLock
    	     do shell script sizeLock
    	     do shell script "killall Dock"
            end try
    end toggleDockLock
     
  13. Jolly Jimmy macrumors 65816

    Jolly Jimmy

    Joined:
    Dec 13, 2007
    #13
    I originally wrote the script with a choice of lock/unlock and cancel but found it pretty pointless seeing as it's really just an ON/OFF switch. Also, it doesn't give you any indication as to the current state and you can click something and have it do nothing. The prompt for the toggle is of course optional but at least you know exactly what's going on and you have the chance to cancel.
     
  14. xsimsimx macrumors member

    xsimsimx

    Joined:
    Sep 26, 2010
    #14
    How about just hiding the dock


    Or else you can lock the dock by onyx
     
  15. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #15
    My point was that you were having the user click "Ok" to perform the action, but there really wasn't a choice. It was pointless to involve the user when you were just performing the opposite action of the current state.

    In regards to it not giving the current state, the user should know what the current state is. It isn't that the script does nothing, it does exactly what the user intends, which may not make a change.

    I added status to this one.

    Code:
    (*
    
    	Dock Size and Contents Lock/Unlock Toggle
    	
    *)
    
    -- Get the current status
    set contentsLockMessage to getCurrentDockContentStatus()
    set sizeLockMessage to getCurrentDockSizeStatus()
    
    -- Ask the user if they want to Lock or Unlock the Dock
    set userPrompt to (display dialog "Do you want to Lock or Unlock the Dock?" & "
    " & "
    " & "Current Status:" & space & contentsLockMessage & "," & space & sizeLockMessage buttons {"Lock", "Unlock", "Cancel"} default button "Lock" with title "Dock Lock/Unlock Toggle")
    set userAction to button returned of userPrompt
    
    -- Turn the user request into a useable value
    if userAction is "Lock" then
    	set toggleValue to true
    else if userAction is "Unlock" then
    	set toggleValue to false
    end if
    
    -- Perform the requested action
    toggleDockLock(toggleValue)
    
    ------------------------------------------
    -- Functions --
    ------------------------------------------
    to toggleDockLock(toggleValue)
    	set contentsLock to "defaults write com.apple.dock contents-immutable -bool " & toggleValue
    	set sizeLock to "defaults write com.apple.Dock size-immutable -bool " & toggleValue
    	
    	-- Perform the requested action
    	do shell script contentsLock
    	do shell script sizeLock
    	do shell script "killall Dock"
    end toggleDockLock
    
    to getCurrentDockContentStatus()
    	try
    		set contentsLockStatus to do shell script "defaults read com.apple.dock contents-immutable"
    	on error
    		set contentsLockStatus to ""
    	end try
    	
    	if contentsLockStatus = "0" or contentsLockStatus = "" then
    		set contentsLockMessage to "Contents unlocked"
    	else if contentsLockStatus = "1" then
    		set contentsLockMessage to "Contents locked"
    		
    	end if
    	
    	return contentsLockMessage
    	
    end getCurrentDockContentStatus
    
    to getCurrentDockSizeStatus()
    	try
    		set sizeLockStatus to do shell script "defaults read com.apple.Dock size-immutable"
    	on error
    		set sizeLockStatus to ""
    	end try
    	
    	if sizeLockStatus = "0" or sizeLockStatus = "" then
    		set sizeLockMessage to "Size unlocked"
    	else if sizeLockStatus = "1" then
    		set sizeLockMessage to "Size locked"
    	end if
    	
    	return sizeLockMessage
    end getCurrentDockSizeStatus
     
  16. Jolly Jimmy macrumors 65816

    Jolly Jimmy

    Joined:
    Dec 13, 2007
    #16
    Since when is providing user feedback pointless? Want to know what is? Buttons that do nothing. There's no need to over complicate things.
     

Share This Page