Application into Dock

Hi Folks,

the topics about putting an application into the Dock are quite old, thats why I kindly
ask you wheter there is a solution on putting an application into the dock…

I found a perl script here, but I am not sure how to handle it…

Thanks for your time and your help!

Best regards,

Stefan

The problem is that the state of the dock is stored in ~/Library/Preferences/com.apple.dock.plist in a rather complex way. Persistent apps are stored as an array and I wouldn’t care to try to modify one of them. The first one of mine looks like this:

Actually, it’s quite easy to add apps to the dock. Lots of people look at the entries in the plist file and freak out at it’s complexity. But, what you don’t know unless you try it is that all of the crazy, encrypted stuff is generated dynamically for you. All you need to do is the following, and the rest is taken care of by the dock itself…

set theAppPath to "/Applications/Chess.app"
try
	set theShellScript to "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
	do shell script theShellScript
	do shell script "killall -HUP Dock"
end try

j

1 Like

Thanks for that, Jobu; but it begs the question: “How do you remove an item from the dock?”

The ‘delete’ function of the defaults command-line tool isn’t as powerful as the functions for writing entries. Unfortunately, I don’t think deleting nested keys is possible using just the defaults command. For this kind of power, you’d need to use something like obj-c and it’s nsdictionary methods in a cocoa application to work with plists at this level. Some of the osax, other languages, and of course some custom brute-force applescript could also potentially handle this… but these add even more layers of complexity. Compared to simply dragging the item out of the dock, it hardly seems worth it unless you had a good reason.

j

Hi Jobu, hi Adam,

thanks a lot for your help! It solves this issue…

Best regards, and again Thanks a lot…

Stefan

Hi Jobu, hi Adam,

what can I do if the name of the Appl contains ’ ?

I tried this, but the File will be inserted without the ’

When I drag the application into the Dock then it will be displayed as follows: Web’n’walk Manager MacOS but now:
Webnwalk Manager MacOS - thats why the Application will not be found…


set para to "'"
set theAppPath to "/Applications/Web" & para & "n" & para & "Walk Manager MacOS.app"
try
   set theShellScript to "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
   do shell script theShellScript
   do shell script "killall -HUP Dock"
end try

Thanks for your help,

Stefan

Hi Folks,

its very funny, it seems like it is not possible to add Applications with ’ dynamically into the dock…

I tried in the Terminal or from AS - even if the script has the ’ stored in the variable it will not
be shown in the com.apple.dock.plist…

Thanks for your time…

Best Regards,

Stefan

HI Folks,

by reading the code much better I found out that I have an ’ in the code…

"defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"

Thats why the ’ inside the application is not working…

Thanks for your time…

Best regards,

Stefan

HI Folks,

this solves the issue:


"defaults write com.apple.dock persistent-apps -array-add \"<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\""


Best Regards,

Stefan

Hi Stefan

two personal notes:

¢ I would always avoid any special characters in file names
¢ I don’t like (third party) applications, which install automatically an icon in the dock.
This is my business to do it or to leave it

Hi Stefan,

I totally agree with you,
but Marketing wants the application to be called “web’n’walk Manager MacOS” and
the people from t-mobile germany want the application to be put in the dock (similar to Launch2Net)…

So what to do?

Best Regards,

Stefan

Ja ja, “Wes Brot ich ess, des Lied ich sing”
(in english: He who pays the piper, calls the tune)

Wow, a commercial project, congratulations.
No comment about T-mobile :wink:

I wanted to avoid making comment about this issue, but since StefanK started, I’ll add my 2 cents.

While it may seem trivial to add an app to a users dock in a selfish attempt to push one’s wares or to toot one’s own horn, this is hardly an ethical or standard practice and should be avoided unless under the strictest of terms. The key is to ASK FIRST. Once you have clearly told the owner/user of the computer that you would like to add something to their computer… whether it’s to the dock, the menu bar, their hard drive, whatever… ONLY THEN should you continue with your installation or changes. You should NEVER put something in the dock without the user explicitly telling you it’s OK to do so. I personally have strict terms by which I organize my computer environment, and there is little more insulting to me than someone dictating to me how my computer should be set up. If adding to the dock were a difficult thing for the user to do, I might understand wanting to put it there, but it’s simple and can be done in a few different ways. During installation or on first launch it is quite simple to merely ask the user if they want to put it in the dock or not. Don’t claim to know what’s best for your users and try to make the decision for them.

A wise, um, movie character once said “With great power comes great responsibility”. This seems like appropriate advice in this case. Just because you CAN put it in the dock, doesn’t mean you SHOULD. There are tens of thousands of pieces of software in the world, and nearly every one of them chooses NOT to mess with the dock. I believe that doing it your own way is dangerously defiant. For example, I have a printer driver/software package that insists on resetting its preferences every time I upgrade my system software, and it re-displays a status menu in the menu bar every time I upgrade. I must manually launch the program and change the setting every time, because they didn’t take the time to develop software that works like other software does. Unfortunately there’s no way to have both the driver software installed and not also have the code that keeps displaying the menu item installed, so I’m bound to dealing with the menu every couple months or getting a new printer. A user should NEVER consider not using your product because of the poorly designed or annoying software that comes with it!

Remember, your users are not ALL idiots. Yes, some of them probably need you to put it in the dock for them, because they would never otherwise find your software on their machine after you install it. But to protect the rights of your other users, I strongly suggest doing at least one of the following…

  1. Ask them first. During installation or at first launch, simply pop up a dialog and see if they want it there or not. If they say no, respect that and don’t ever ask them again.
  2. Give them an option later. Add a preference (perhaps something similar to the checkbox in many of the pref panes in the system preferences) that adds it to the dock if they decide later that they want it there. As my previous post states, “managing” your app’s presence in the dock will require a little more work, if it’s even possible or reasonable to accomplish at all, but probably worth it if this is a feature the people signing your paycheck can’t live without.

If you search around, you’ll find a lot of people who get pretty upset when an app decides to impose itself on their dock. And while apple has even been known to do this, that doesn’t make it right. As developers we must remember that we don’t own our user’s computer, and while we are sometimes required to make decisions for them that effect the functionality of our software, we are also responsible for making sound decisions about things that are merely bells and whistles. Adding too many things that go against the grain might ultimately lead to your product’s demise, as your users will simply decide it’s not worth the annoyance of keeping it around.

If all you have to do is ask first, I fail to see why you would decide NOT to take this easier and more responsible route.

As far as the naming of files and applications goes, there are many reasons NOT to use anything but alphanumeric/websafe characters. A-Z, 1-0, and ‘_’. You of course can also use space in your names when installing on a computer, but for universal compatibility and simplifying distribution, sticking to simple naming conventions is preferred. And as you’ve already found, adding a single-quote to your apps name opens you up to a whole range of potential conflicts. How can a user USE your software as they see fit if they can’t do anything but click on it’s icon in the dock and follow the narrow path you’ve laid out before them? What if they want to add your software to their automated workflow, but they can’t launch it via the terminal or a script because no scripting language can handle it’s name? What if you decide to add hooks for third-party support or plugins, and people like applescripters can’t write a script because you decided to make your name “pretty” instead of functional?

All of this begs the question, ‘Do you care about your customers… or just your profits?’ Consider that perhaps it is your customers who know best. Provide them with a piece of software that fits INTO their life, not one which they must rearrange their life around. Respect your customers. Ultimately it’s they who are paying you for what you’re creating today.

Just my opinions, of course…:o
j

Hi jobu,

I agree totally with your 2 cents. :slight_smile:

There is no need for it. Every application, which appears in the dock when opened,
can be kept in the dock permanently with it’s contextual menu

I second those comments, Jobu - and add that I feel the same way about any web site that alters the size of my browser window. I have it set as and where I like it to be and resent anyone moving it or resizing it.

Yeah, I was originally going to go on and on about other ways to work with the dock, and to discuss lots of reasons why you shouldn’t mess with the dock at all. Instead, I decided to list what I thought was an “acceptable alternative” to just leaving it entirely up to the user to put it in the dock manually. By no means think that I encourage doing anything with the dock other than my first option… give them a choice and do it only if they approve. Other than that it should be entirely up the the users. Considering the ease with which you can add and remove things from the dock, it kind of shows the whole point about how marketing people shouldn’t really be in charge of software development or web development in the first place. Just let people do it themselves. :rolleyes:

The reason I listed the second option, is because I have some experience working FOR someone else, and I know how frustrating it can be to go back to “the man” and try to convince them that all of their “amazing, groundbreaking” ideas are all just crap and aren’t done by anyone else for a reason. There are times when doing things in an untraditional way, or when doing things for the user are desirable, but I can’t speculate as to what exactly his software does or whether it would be appropriate to make up his own rules. Take something like a scanner utility or some small piece of shareware (like most of my work). Making the assumption that the user wants its icon taking up permanent space in the dock would be offensive to most people. Alternately, say I spend 800 dollars on a graphics program. Chances are, it’s gonna get some use, and I’d be a little less offended if they plopped it in there for me. I still don’t like it, but at least they’ve got the meat to back up their claim that it SHOULD be available to me all the time. I still maintain that it should be my choice, no matter what software it is. Considering that it’s a product for t-mobile, I jump to the conclusion that it has something to do with my cell phone. I can think of nothing that I’d want to buy or install from tmobile that would be SOOO important that I couldn’t live without it. Simply respect me and my lifestyle, and ask me if what I’m installing is that important to me. If it is, shabang… add the icon for me. Otherwise, don’t even think about it.

Marketing directors are quick to dish out their own personal take on computer development through their own thin, profit-driven view of the world… but ultimately the consumer will define what they want in their products. It is up to those of us who have spent the time paying attention to what users want, both by developing products for others and by being devoted computer users ourselves, to convey to those with the paychecks what is expected of us when releasing software to the world. And as you said StefanK, yes there are times when we are confronted with doing things that we neither agree with nor want to do, but we must in the interest of our livelihood. I have come to realize though, that the reason “You” (the proverbial you, i.e. all of us) are creating that project for someone else, is because you are an expert at what you do. While they have the money and the marketing prowess to create products that people want to buy, you have been given the task of creating software using YOUR talents and abilities. If your experience contradicts what your employer asks of you… especially when it compromises your beliefs or values either personally or professionally… I feel it’s your duty to at least state your position and your reasons, and to offer viable alternatives. Once you’ve done that, if the customer still persists, you either roll your eyes and carry on, or you embrace the obvious alternative.

As I said, while this may seem a trivial thing (putting something in the dock) you must consider that to others something so minor may not be so trivial. What I’m trying to convey is that this really shouldn’t even be an issue. The only changes you should EVER make to a users workspace are things you’ve asked permission to do… PERIOD. I’d be willing to bet that there are a significant number of people who would throw it in the trash merely at the knowledge that it would put its icon in the dock without asking… and a great deal more who would find it very offensive. While there will be some who just don’t care, it seems wise and morally correct to simply take the one extra step to give your users the choice. Choice makes us human… choice makes us free.

Take care, and don’t think about putting anything in MY dock… :smiley:
j

PS, Adam, don’t get me started about window resizing. With popups it’s fine, but not the main window damn it! Grrr…

What if the application does not exist in the Applications folder? For example, I have an application that I want to have moved into user’s dock that exists in the current users folder/Library/Application Support.

I don’t know why this is not working?

set theAppPath to "~/Library/Application Support/KillQKeys2.app"
try
	set theShellScript to "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
	do shell script theShellScript
	do shell script "killall -HUP Dock"
end try

I guess the plist expects the full path (no tilde abbreviation)

Thank you again Stefan, this was easier than I expected.

set theAppPath to POSIX path of ((path to current user folder as text) & "Library:Application Support:KillQKeys2.app")
try
	set theShellScript to "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
	do shell script theShellScript
	do shell script "killall -HUP Dock"
end try