Home
Posted By: Virtual1 undo poof out of dock? - 02/01/10 05:48 PM

More than once I've been working on a machine and accidentally poofed something from the dock when trying to open an app from there.

Is there any way to undo this? or to find out what you just poofed?
Posted By: Hal Itosis Re: undo poof out of dock? - 02/01/10 07:32 PM
No undo.

You'd need a (backup) dock.plist from before the move to compare to the current:

defaults read com.apple.dock |sed '/^ *"_CFURLString" = /!d;s///'

If this happens a lot, maybe the first thing to do when working on a machine is to backup the dock.plist (and whatever else necessary). Then when you're finished, just copy 'em back.
wink

--

Although, there seems to be some sort of (SQL?) database cache file at ~/Library/Preferences/com.apple.dock.db -- but i don't know how to "decode" it. Yikes, i just ran strings on it...

strings ~/Library/Preferences/com.apple.dock.db

...and i couldn't believe the junk Apple has squirreled away in there!!!
(try it and see).
Posted By: Virtual1 Re: undo poof out of dock? - 02/02/10 04:36 PM
The specific problem I'm having is when working with someone else's machine. Sometimes if it's behaving erratically or laggy it's easy to accidentally drag a click in the dock and poof something when trying to work with desktop icons that users have placed just above (or partly under) their dock.

Of course that often means I didn't catch what I managed to poof. So (A) I don't know what it was and (B) I'm not going to be having a backup of the plist....
Posted By: Hal Itosis Re: undo poof out of dock? - 02/02/10 05:37 PM
Originally Posted By: Virtual1
(A) I don't know what it was and
(B) I'm not going to be having a backup of the plist.

If this happens a lot, maybe the first thing to do when working on a machine is to backup the dock.plist (and whatever else necessary). Then when you're finished, just copy 'em back.

(What else can i say? -- i don't think any other choice exists -- visit your optometrist perhaps?).

EDIT: take a screenshot maybe (command-shift-3),
Posted By: Virtual1 Re: undo poof out of dock? - 02/03/10 12:03 AM
it doesn't happen enough to warrant additional preparations, I was just hoping there was something I could do on the rare now and then that it happens, besides cuss and mumble about having no idea what just went POOF
Posted By: roger Re: undo poof out of dock? - 02/03/10 12:16 AM
there definitely should be a way to undo that.
Posted By: joemikeb Re: undo poof out of dock? - 02/03/10 11:57 PM
There is. It is called Time Machine.
Posted By: Virtual1 Re: undo poof out of dock? - 02/04/10 03:50 AM
I didn't know time machine could restore missing dock items. How do you do that?
Posted By: MicroMatTech3 Re: undo poof out of dock? - 02/04/10 04:29 AM
You could restore the plist file at ~/Library/Preferences/com.apple.dock.plist .
Posted By: Hal Itosis Re: undo poof out of dock? - 02/04/10 04:38 AM
Third Base!
Posted By: dkmarsh Re: undo poof out of dock? - 02/04/10 01:16 PM

Originally Posted By: Virtual1
it doesn't happen enough to warrant additional preparations, I was just hoping there was something I could do on the rare now and then that it happens, besides cuss and mumble about having no idea what just went POOF

Since Virtual isn't sufficiently motivated by the problem to back up the specific file which holds the desired information, he may not want to bother locating and navigating through a Time Machine backup and restoring the file in question, assuming a Time Machine backup is available.

Plus, in my experimenting (OS X 10.5.8), restoring a saved copy of com.apple.dock.plist, then running killall Dock, failed to restore the poofed application to the relaunched Dock. (Same with com.apple.dock.db.) So, if a logout/login or restart are required, that makes restoring a backed-up plist even more time-consuming.

How about scripting the production of a simple list of the Dock's contents, requiring just a double-click at the beginning of a session? A comparison of the list, in the rare instance it was required, with the extant Dock should make it easy to identify the poofee.

Parsing the XML and extracting the item names shouldn't be too tough; I might even try it myself.
Posted By: alternaut Re: undo poof out of dock? - 02/04/10 01:49 PM
Originally Posted By: dkmarsh
Parsing the XML and extracting the item names shouldn't be too tough; I might even try it myself.

Ahh! I spy yet another great little FTM utility! tongue
Posted By: Hal Itosis Re: undo poof out of dock? - 02/04/10 05:58 PM
Originally Posted By: dkmarsh
Plus, in my experimenting (OS X 10.5.8), restoring a saved copy of com.apple.dock.plist, then running killall Dock, failed to restore the poofed application to the relaunched Dock. (Same with com.apple.dock.db.) So, if a logout/login or restart are required, that makes restoring a backed-up plist even more time-consuming.

Perhaps if the script would quit Finder (quit, not relaunch), delay/sleep for a second (or 2), write the plist, and then resurrect Finder, maybe. . .
Posted By: MicroMatTech3 Re: undo poof out of dock? - 02/04/10 11:08 PM
The following worked on my MacBook Pro Core 2 Duo running Mac OS X 10.6.2. Before I began, I noted where Disk Utility was in my Dock.

Before subjecting the Dock to unintentional poofing, make backups of the following files, by selecting them in the Finder and typing Command D:

1. ~/Library/Preferences/com.apple.dock.plist

2. ~/Library/Preferences/com.apple.dock.db

We now have two new files:

~/Library/Preferences/com.apple.dock copy.plist

~/Library/Preferences/com.apple.dock.db copy

Remove Disk Utility from the Dock. Poof!

Delete:

~/Library/Preferences/com.apple.dock.plist

~/Library/Preferences/com.apple.dock.db

Rename:

~/Library/Preferences/com.apple.dock copy.plist to ~/Library/Preferences/com.apple.dock.plist

~/Library/Preferences/com.apple.dock.db copy to ~/Library/Preferences/com.apple.dock.db

Launch Activity Monitor, located in /Applications/Utilities. Force the process named Dock to quit. When the Dock relaunches automatically after a few seconds of sheer Docklessness, note that Disk Utility is right where it belongs in the Dock.
Posted By: dkmarsh Re: undo poof out of dock? - 02/05/10 12:42 AM

Excellent! Thanks for the solution to the restore issue.

In Virtual1's scenario (working on someone else's Mac), this approach requires backing up the specified files, then, in the vast majority of cases—in which no poofing occurs—deleting them at the conclusion of the session (following the Boy Scout credo of leaving things as clean as you found them).

Posted By: MicroMatTech3 Re: undo poof out of dock? - 02/05/10 01:07 AM
dkmarsh,

I had thought that the idea of “leaving only footprints” originated with Colin Fletcher, but this topic may prove more difficult to research than the best method of restoring a Dock:

http://www.clubtread.org/etiquett.php

I never made it to Boy Scout. I was a Cub Scout, and had to endure den meetings in which the den mother’s son was allowed to pester me with his deformed fingernail. We made one interesting trip to a place of geological interest, and that was the end for me. I still think Scouting is a great idea, and wish I could find a royal blue cotton shirt that reminds me of my Cub Scout shirt. I had a reference to the shirt in one of my databases, and of course, I cannot find it now. I guess I am unprepared.
Posted By: roger Re: undo poof out of dock? - 02/05/10 07:48 PM
"Before subjecting the Dock to unintentional poofing,"

"honey, I think I'm going to poof!"

cool

I'm thinking of a "normal" Mac user, and that this must happen not unfrequently. a little Finder Undo would be handy. all this plist stuff is great, but next we'll be bringing out Terminal...
Posted By: Hal Itosis Re: undo poof out of dock? - 02/05/10 09:53 PM
Originally Posted By: roger
I'm thinking of a "normal" Mac user, and that this must happen not unfrequently. a little Finder Undo would be handy. all this plist stuff is great, but next we'll be bringing out Terminal...

Actually, the whole thing would be best wrapped in an AppleScript applet [which itself could make Unix-type calls, if necessary (e.g., not that it's needed, but if there was something that AppleScript doesn't do easily... such as defaults read perhaps, then it could be achieved via the do shell script syntax).]

So the user would run it, and a dialog would ask if we're saving a backup or restoring a poofed dock... and then it would do all the copying, process killing, etc., etc.

Anyway, it could all be reduced to double-clicking an app and then clicking one button in a dialog. The main trick will be remembering to run it early on, to save the backup plist in the first place.

EDIT: At this point i'm still not convinced that "com.apple.dock.db" is anything crucial. From what i've seen of it so far, i'd almost think we'd be doing the user a favor by *erasing* it [and letting the OS build a brand new one (smaller and cleaner) from our preserved plist.]

EDIT 2: BTW, there is also another cache for the dock, but it seems more devoted to icon data (for faster drawing i guess -- probably handy for the magnification feature):

ls -lh /var/folders/*/*/-Caches-/com.apple.dock.*
Posted By: dkmarsh Re: undo poof out of dock? - 02/06/10 05:02 AM

I'm sure it would be easier if I knew how to manipulate text from the command line, but this AppleScript script works on my machine (OS X 10.5.8):

set itemList to {}
set theList to do shell script "defaults read com.apple.dock | grep 'file-label' | cut -c 31-"
set AppleScript's text item delimiters to return
set itemList to text items of theList
set endList to {}
set AppleScript's text item delimiters to " "
repeat with n from 1 to count of itemList
set j to item n of itemList as text
set end of endList to (words of j as text)
end repeat
set AppleScript's text item delimiters to return
display dialog endList as text
set AppleScript's text item delimiters to ""

(Note that any non-'word' characters will be left behind; on my machine, for instance, ViaCAD 2D/3D is displayed as ViaCAD 2D 3D.)

Figuring out how to save this information for potential use and discard it if it turns out not to be needed is left as an exercise for the reader. wink
Posted By: Hal Itosis Re: undo poof out of dock? - 02/06/10 05:42 AM
Heck, why not just copy the whole file: do shell script "cp -fp ~/Library/Preferences/com.apple.dock.plist /tmp/" ... for the backup part, and do the reverse for restore: do shell script "cp -fp /tmp/com.apple.dock.plist ~/Library/Preferences/" [there are basic AppleScript equivalents that could do as well without a "do shell script" statement.]

All that's needed is to display dialog asking whether we're doing a backup or a restore. If it's a restore, we need to kill the running dock (or maybe quite Finder with: ignoring application responses tell application "Finder" to quit -- do the reverse copy from /tmp to prefs/ -- and resurrect Finder with: tell application "Finder" to activate ). Some "delay 2" statements may need to be sprinkled strategically within that block... but that's about 90% of the task there (i think).

edit: i guess the restore routine should check that a backup file exists... else tell the user: "too late dude, no backup found... would you like to backup now instead?"
Posted By: roger Re: undo poof out of dock? - 02/06/10 02:41 PM
well, I consider myself a bit more than an average mac-user, but I rarely use Applescript, and I would guess that most mac-users don't either.

having to know ahead of time that I might accidentally poof something from the Dock so I'd better run a backup script? every time I go to the Dock?

Finder - Edit - Undo Delete from Dock
Posted By: alternaut Re: undo poof out of dock? - 02/06/10 03:20 PM
Originally Posted By: roger
Finder - Edit - Undo Delete from Dock

Oops: Can't Undo shocked
Posted By: Gregg Re: undo poof out of dock? - 02/06/10 03:23 PM
Or, borrowing from AutoDesk, a simple Oops command which "undoes" whatever you did last would be great. In AutoCad, multiple Oops commands continue to undo the previous action until you get to the last saved state of the file. But, a simple return will allow you to continue to Oops some more.
Posted By: roger Re: undo poof out of dock? - 02/06/10 03:48 PM
Originally Posted By: alternaut
Originally Posted By: roger
Finder - Edit - Undo Delete from Dock

Oops: Can't Undo shocked


yeah, just seems strange that OSX can't keep track of an alias.
Posted By: Hal Itosis Re: undo poof out of dock? - 02/06/10 05:03 PM
Originally Posted By: roger
well, I consider myself a bit more than an average mac-user, but I rarely use Applescript, and I would guess that most mac-users don't either.

having to know ahead of time that I might accidentally poof something from the Dock so I'd better run a backup script?

Finder - Edit - Undo Delete from Dock

That's not what this is about. I mean, i agree with you... it "should" be there. But it's not. So, some workaround is needed.

[the other thing is... this wasn't a general issue about one user and their Mac. It was originally about Virtual1, who works on a bunch of Macs every day, that don't belong to him.]

To summarize: we agree that a "Undo" should be there... and, i think we also agree that it's not there.

So, i guess the remaining question is: does a script solution interest anyone? grin


Originally Posted By: roger
every time I go to the Dock?

No... that would only be needed for V1, who works on a bunch of *different* Macs every day, that don't belong to him. [and even there, he would just backup once... as soon as he logged in.]

A more general solution [for users operating their own machines] would have the "backup" part automated (perhaps running every time the dock plist gets modified... or maybe just once an hour). In that scenario, all we would need is to run the script and choose 'Restore'.
Posted By: Hal Itosis Re: undo poof out of dock? - 02/06/10 05:18 PM
Quote:
perhaps running every time the dock plist gets modified...

Oops, that could be a bit risky... because it might accidently back up the poof. grin

Maybe every 10 minutes or something.
Posted By: dkmarsh Re: undo poof out of dock? - 02/06/10 06:27 PM

Why would users operating their own machines even need a solution? If I accidentally poofed, say, ViaCAD 2D/3D off my Dock, and knew that I'd poofed something but couldn't immediately tell what...

...so what?

I either wouldn't miss it, or, at some subsequent point, would begin to think, "what a pain it is to go into /Applications [or Spotlight, or my /Applications folder in the Dock, or one of the inexhaustible supply of third-party launchers (if I had any)] every time I want to run ViaCAD; I should keep it in the Dock."

At which point, I would add it to my Dock—whether I remembered it having previously been there or not. laugh
Posted By: roger Re: undo poof out of dock? - 02/06/10 06:43 PM
Hal and dk:

good points, all!
© FineTunedMac