PDA

View Full Version : Script that hides the dock




Photog
Sep 20, 2006, 07:47 AM
I am looking for any clue on how to write a script that would close the dock every 5-10 minutes. I am a beginner at the scripting world. I have multiple users on my machine and they tend to unhide the dock. It is possible to have a script running in the background to hide the dock every few minutes.

Thanks in advance.



MacBoobsPro
Sep 20, 2006, 07:52 AM
I am looking for any clue on how to write a script that would close the dock every 5-10 minutes. I am a beginner at the scripting world. I have multiple users on my machine and they tend to unhide the dock. It is possible to have a script running in the background to hide the dock every few minutes.

Thanks in advance.

Does auto hide not do the job?

Photog
Sep 20, 2006, 07:55 AM
It does but I would rather have it scripted so everytime I sit down I do not have to hide the dock. A simple script would hide it for me.

MacBoobsPro
Sep 20, 2006, 08:07 AM
It does but I would rather have it scripted so everytime I sit down I do not have to hide the dock. A simple script would hide it for me.

Oh i see :)

I know its not a script but could you not put the sytem pref icon in your dock? That way you can change auto hide in 3 clicks. System Pref > Dock > Autohide. Just a suggestion, i dont know scripting so i cant help in that way.

Sharewaredemon
Sep 20, 2006, 08:53 AM
Well there is a hotkey to do it.

Command Option D, I don't see why that's so hard to do...

Am I confused about what you want to do?

MacBoobsPro
Sep 20, 2006, 09:01 AM
Well there is a hotkey to do it.

Command Option D, I don't see why that's so hard to do...

Am I confused about what you want to do?

...Boom!

savar
Sep 20, 2006, 09:34 AM
I am looking for any clue on how to write a script that would close the dock every 5-10 minutes. I am a beginner at the scripting world. I have multiple users on my machine and they tend to unhide the dock. It is possible to have a script running in the background to hide the dock every few minutes.

Thanks in advance.

I don't think you can do it with a script -- but I'm not a scripter so I could be wrong.

It's definitely possible using Cocoa. There are some undocumented APIs that I found to manipulate the dock. I'm sure others have found them too and explained them, try google.

Unorthodox
Sep 20, 2006, 09:43 AM
I tried to make a script to do so but I can't figure out how to select menu items within sub-menus.

You could try remembering the shortcut "option command D"
That toggles the dock hiding on and off.

I can make a script that simulates that keystroke but then you just have a script that toggle the dock hiding.

mufflon
Sep 20, 2006, 10:04 AM
I believe you can kill the dock if you know the pid (?), but it might resurface / make the system less stable

Unorthodox
Sep 20, 2006, 10:23 AM
I believe you can kill the dock if you know the pid (?), but it might resurface / make the system less stable
If you kill the dock it just starts up again.

mufflon
Sep 20, 2006, 11:59 AM
If you kill the dock it just starts up again.


I just never seem interested in trying this kind of things, alas it was worth a shot :)

Unorthodox
Sep 20, 2006, 02:43 PM
Yay!
I figured it out.
Set the top variable (min_to_delay) to the amount of minutes you want to tick by before the it tries to hide the dock again.

Copy past this into "Script Editor", save it as an application, give it a name, a location and fire it up.
By default it will hide the dock every 10 minutes.

The drawbacks are:
-The only way to quit this script is to force quit it (command option esc)
-It adds another icon to the dock

Since you want to hide the dock the icon might not bother you.
If it does you can disable it using this (http://www.macupdate.com/info.php/id/12516) application.
If you do choose to hide the dock icon the only way to quit this script will be to open "Activity Monitor", select the it's process name and force quit it.

set min_to_delay to "10" --set this to how many minutes you want to go by before hiding the dock

set sec_to_delay to min_to_delay * 60
repeat
tell application "Finder"
activate
end tell
tell application "System Events"
if UI elements enabled then
try
click menu item "Turn Hiding On" of menu "Dock" of menu item "Dock" of menu "Apple" of menu bar 1 of process "Finder"
end try
delay sec_to_delay
else
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
display dialog "UI element scripting is not enabled. Check \"Enable access for assistive devices\" to use this script"
end tell
end if
end tell
end repeat

Photog
Sep 27, 2006, 07:52 AM
Thanks, here is the one someone at my work recently made for me.

on idle

tell application "System Events" to tell process "Finder" to tell menu bar 1 to tell menu "Apple" to tell menu item "Dock" to tell menu 1 to get name of menu item 1
-- return result
if result is "Turn Hiding On" then
tell application "System Events" to keystroke "d" using {command down, option down}
else
-- quit me
end if

end idle