Tuesday, February 12, 2013

How to set MS Word 2010 as default application for all docx and other types?


Solution

Visit: http://ubuntuforums.org/showthread.php?t=1940522

BY: forrestcupp

Preface: This is a howto, not a question.

Today, after beating my brains out trying to install Office 2007 with Wine 1.4 in Precise, I ended up resorting to using PlayOnLinux. What I learned about PlayOnLinux is that it makes installing things a dream, but it makes the general usability of those things an absolute nightmare. When I had Office 2007 installed with Wine, I could easily set filetype associations in Nautilus to Word and Excel. When I installed Office 2007 in PlayOnLinux, it didn't leave any way to associate filetypes. Also, PlayOnLinux created nice shortcuts to the apps on the desktop, but it didn't create any gnome-desktop launchers that will show up in Dash in Unity or Gnome Shell.

After a lot of hard work and headaches, I finally figured out how to do both of those things, so I thought I would share that experience for future reference, and for anyone else who might need it.

When you are preparing to do this, be aware that you will have to create two separate .desktop files for each Office program (Word, Excel, etc.). The first section creates a .desktop file so that a new instance of Word can be launched from the Dash. The second section creates a second .desktop file for associating file types.

Creating a .desktop launcher file

This creates a .desktop file so that a new instance your Office programs can be launched from Dash.

Open a terminal, and enter this command: Code:

gnome-desktop-item-edit ~/.local/share/applications/ --create-new

In the window that comes up, first enter a name for your launcher. For Microsoft Word, we'll enter Microsoft Word as the name. Then in the "Command" box, for Word 2007, we'll enter this code Code:

playonlinux --run "Microsoft Word 2007"

For Excel 2007, you would enter "Microsoft Excel 2007" leaving the quotes in it. For anything else, you just would put whatever app name shows up in the PlayOnLinux window, and put that name in quotes. After this, you can click on the icon and use the file browser to point it to whatever icon you want to use for that launcher.

After doing this, your app launcher should show up by doing a Dash search.

Associating files with MS Office that was installed with PlayOnLinux

This creates a second .desktop file for associating your file types.

Step 1 - creating a .desktop launcher for association Since PlayOnLinux installed apps don't show up in the "Open With" dialog in Nautilus, you have to create a custom command for Nautilus. This used to be easy to do with the GUI, but since they changed to Gnome 3 in 11.10, you can't do that anymore. Never fear, that's why we have the command line. Open a terminal, and cd to a folder that has a .doc or .docx file. Once you're in that folder, note the name of your Word document file, and type: Code:

mimeopen -d filename.doc

Of course you would type .docx if that's what type of file it is. When you type this, it will give you options of what you want the default app to be for that file. Enter whatever number says "Other" so that you can enter a custom command. For that custom command, enter the following for Word 2007: Code:

playonlinux --run "Microsoft Word 2007" z:%f

Note, that it will try to open the file with Word, and at this point it will not work. By the time you're done, it will work properly when you double click it in Nautilus.

Now open up Nautilus, press Ctrl+H if hidden files aren't showing, and navigate to ~/.local/share/applications and find the .desktop launcher file with something like "playonlinux_userdefined" in the name. Change that name to something like Word.desktop. Now you can right-click on a .doc or .docx file, go to Properties, and go to the "Open With" tab, click "Show Other Applications" and find "Word.desktop" in the list. Now, that filetype is associated with Word, and you can go through all of those steps again substituting the right names for Excel and Powerpoint.

Step 2 - making it work properly Unfortunately, what you just did won't work if there are spaces in the file or folder names. But we can fix that, too.

Open Nautilus and navigate to ~/.PlayOnLinux/shortcuts. Double click on each of the shortcuts that were made for Word, Excel, and Powerpoint, and choose to Display the file in Gedit. At the end of the script, you should find this code: Code:

$@

Change that code for the following code in each shortcut script, and save the files. Code:

"$(echo "$@" | sed -e 's:/*/:\:g')"

Make sure you leave the quotes in. That code will take the path and filename and convert any spaces to be readable by Word, Excel, or Powerpoint when you open the file.

Since both desktop files will show up in a Dash search, I suggest not assigning an icon to this one to prevent confusion.

Now, you should be able to navigate to any MS Office file in Nautilus, double click on it, and it will open properly.

I'm not an expert, and this is just the findings of my experience. Hopefully it works for you, too.

Edit: I found all of this information scattered all over the net, but I need to give credit to wojox for helping me fix a problem with the bash code I found for the shortcut script.

No comments:

Post a Comment