Determining default application by extension

Hello everyone,
Desktop class is a beautiful step forward in Java. It can launch applications in various modes, depending on the document file type, so that:
Desktop.getDesktop().open(new File("test.odt"));will open the test.odt document in an OpenOffice instance.
But what if I just want to know what program is associated to the "odt" extension?
Here's my real problem:
I might need to open files with unusual extensions using usual programs, without the chance to edit application/extension association. So I'd like to be able to ask Java "What's the default word processor?", that in other words is "with what program would you open the .doc extension?"
Do you have any idea on how to do that (assuming it's possible).
Thanks a lot in advance
Edited by: Simone.Pezzano on Oct 14, 2009 1:04 AM

JoachimSauer wrote:
DarrylBurke wrote:
If a program generates a .gtf file (an extension the OS does not know) and I know I want it open with the default word processor (the one that opens the .doc files)
I must ask the OS what program it has configured to open the .doc files1. If the file is in Word Document format, WIndows / MS Office is smart enough to open it in Word, regardless of the extension.Really? I was under the impression that Windows doesn't look at the content, unlike modern Linux desktops (which even complain sometimes when the extension doesn't match the content!).Windows might not, but Word does. Navigating to something with the "wrong" extension (I believe the dialog gives a 'show all' option) it'll just give it a whirl. Seriously, what else is it going to do? What else is anything going to do? Think of any software you ever wrote that read a file of a specific format. The only foolproof way to know if the file format is right, is to try and load it in.
File extensions really only have any meaning to the OS, even then not much. Unixes themselves don't have such a concept at all, although some window managers do.

Similar Messages

  • Open default application based on file extension

    I'm developing a small AppleScript that opens URLs of format "myapp:http://domain.com/data/filename.ext"
    where 'myapp' is actually the applescript registered to be launched using "CFBundleURLName"
    I wonder how to launch/open the default application registered for ".ext" file extension.
    I found how to determine the default application based on a Real file:
    default application of (info for POSIX file "/path/filename.ext")
    Is it possible to determine the app based only on extension (i.e. the file itself doesn't exists yet).
    I found that there is a function "LSGetApplicationForInfo" (https://developer.apple.com/library/mac/documentation/Carbon/reference/LaunchSer vicesReference/Reference/reference.html)
    but have no idea how it can be used in applescript.
    Thanks

    set f to choose file
    tell application "System Events" to set finfo to the properties of (f as alias)
    set fileID to type identifier of finfo
    if fileID is "com.apple.iwork.pages.pages" then
              set ftype to "Pages"
    else if fileID is "com.microsoft.word.doc" then
              set ftype to "MS Word"
    else if fileID is "com.adobe.pdf" then
              set ftype to "Preview"
    else
              set ftype to "Unknown"
    end if
    display dialog "App is " & ftype
    To determine the file type, use:
    set f to choose file
    tell application "System Events" to set finfo to the properties of (f as alias)
    set fileID to type identifier of finfo
    display dialog fileID

  • Default Application - extension kmz

    When I create a kmz file (used in GPS and Google Earth), the default application to open it is Photoshop. I want it to be Google Earth.
    I can change the default for one file, but when I try to change for all files, it flips back to Photoshop. I have "Default Apps" installed in my control panel and when I try to change the default for that extension using that program / control panel, the same thing happens - it jumps back to Photoshop.
    Any suggestions?
    I have recently checked my hard drive and it goes through a long sequence of changing permissions in one direction, then back. Every time I check permissions, I get this same long log.

    Although that references only through 10.3, yes. Get Info, go to drop down menu, select Google Earth, select Change All. When I do that, it reverts to Photoshop.
    No matter how many times I do that, it always jumps back to Photoshop. Even when I go to the Control Panel - Default Apps, it jumps back. When I go to the program listings in Default Apps, the selection to uncheck .kmz, it is grayed out.

  • Changing file extension default application

    Hello, I periodically change my .avi and .mpg movies default "open with" application to VLC, but although the association change in first place, in a few days the default application mysteriously turn back to QuickTime.
    Is this a bug or an Apple QuickTime appropriative policy? Anyway, is there any way to change to VLC permanently?
    Thanks in advance
    iBook   Mac OS X (10.4.4)  

    Open one of your .avi or .mpg file's "Get Info" window. Pick a new "Open With" application and click the "Change All" button. Confirm your changes.
    From this point on (until you change it again) any time you double-click to open any of these files your chosen app will be used to play the file.
    You can temporarily override these settings by Control-clicking on a icon and choosing a different app from the pull down menu.

  • Change default application for mp3 extensions

    Hello! Thank you in advance to any helpers. This is what I think is wrong:
    I recently had some problems with safari, so I downloaded Firefox. In doing that, I think I changed my defaults for certain extensions, namely mp3.
    So, all email mp3 attachments are opening in another webpage, instead of iTunes (which was the previous default). I do not have any start up disks as this is a hand-me-down laptop and I cannot figure out how to change the default back.
    I tried dragging the file to the desktop, from the email, and it still showed up as a webpage. So I did the whole "get info" and "open using" and "change all" but then the system wanted to change ALL of my itunes files to the .mp3. This was because I had to rename the file (which I know doesn't do much) Any ideas?

    well, I can't click on the file because it is in an email message and if I click, it opens to the internet page with a QuickTime audio player. I've checked all my quicktime stuff, too. I don't think that's it. All the songs in itunes library are ".m4a" The only way I was able to even get to the "open with" and etc. was to drag the .mp3 file onto the desktop and it wasn't even an mp3 file at that point, it was a weblink. I was able to open in in iTunes but it's not an audio file. Itunes put it in my podcast section with an exclamation point next to it.

  • Disabling Appleworks Default Application Status

    When I download Word documents from my students to my desktop the iMac lists the file kind as "com.apple.appleworks.word" even though the document has a "doc" extension. When I try to change the word processing application from Appleworks to Word (in Get Info), it doesn't allow it. I can't change Appleworks from being the default application. Many times Word won't even launch now when I force the document to open with Word. I used to be able to click on the icon and Word would automatically open these documents. Not any more.

    You're taking the right actions—Get Info and change Open With to MS Word (then click Change All to apply the instruction to all AW files).
    That the Mac won't allow you to do this is probably a permissions issue. Get Info on one of the files and check the Permissions and Ownership section to determine if you can Read and Write. If you can only Read, you may need to change (or get the file's owner to change) permissions to allow you to Write before changing the Open with association of the file.
    One thing you might try—create a new AppleWorks word processing file (using AppleWorks, and while logged on to your usual account). Save and Close the file, then Get Info, change the Open with association and click the Change All button.
    As an alternative, you should be able to open the files in Word by dragging the file icon onto the Word icon in the Dock.
    This assumes, of course that MS Word is able to translate and open the files (which your message indicates is the case).
    Regards,
    Barry

  • Unable to read the dictionary of the application or extension...

    I had previously installed the HP Color LaserJet 3600 driver from the install CD under Tiger. I recently did an archive and install of Leopard, then ran all the system updates. (Currently at 10.5.5)
    When I insert the 3600 CD, though, I get a bunch of jibberish (parts of images, etc.) and a MAC OS X directory. The installer inside that directory attempts to be opened with Script Editor, though, and gives an error: "Unable to read the dictionary of the application or extension because it is not scriptable." followed by "The document 'HP Color LaserJet v5.6.1.069' could not be opened."
    Previously this would launch the HP installation program that would install the driver. Now, it's like it's not a recognized program or something. I downloaded the driver from the HP website to try it that way (clj3600MacOSX.dmg) with the same result. The .dmg file opens a disk image with the "HP Color LaserJet v.5.6.1.069" file in it...same result. Cannot open.
    I know this program ran fine under Tiger...and a co-worker got it to run after doing an upgrade to Leopard (instead of archive and install.)
    When I downloaded the HP 4300 installer dmg, it launches a .mpkg file and Get Info says it's set to open with "Installer (default)". The 3600 file, though is set to open with "Script Editor (default)". I've looked to set it to Installer, but don't know where it is...it's not in Applications or Utilities folder.
    I then right clicked on the installer file and selected "Show Package Contents". In the window that was displayed, there was a Contents folder. Inside that folder was a file called "HP Color LaserJet v5.6" with no file extension (Get Info doesn't show an extension either,) but it has a VISE logo. Opening that file launches the VISE installer and performs the setup.
    So, by jumping through hoops and getting lucky, I was able to install the driver.
    The bigger issue, though, is why the installation CD and/or .dmg file downloaded from HP's website cannot run the installer as usual...why are they set to open with Script Editor as the default application...and how can I fix it so that other disks won't have the same problem?
    [I originally posted this in the Printers forum, but it appears it's not a printing problem...it's an OS problem...]

    Installer.app is in /System/Library/CoreServices/

  • How to set my default application...not working

    My company has nearly all adobe applications installed from PageMaker 6.5 through InDesign 5.5. We use them all frequently. I'm trying to set my defaults on the Mac Pros and it is not working.
    Specs if Needed:
    OSX 10.6.8 
    Model Identifier:          MacPro5,1
      Processor Name:          Quad-Core Intel Xeon
      Processor Speed:          2.8 GHz
      Number Of Processors:          1
      Total Number Of Cores:          4
      Memory:          6 GB
      Boot ROM Version:          MP51.007F.B01
    +BootCamp dual boot Windows 7
    We proof out all files in the version that it comes to us. Our customers are on different versions than the most current, and it's driving us crazy that we can't set the defaults for
    each Adobe application. For Instance,
    We want for Defaults:
    Photoshop = CS4
    InDesign = CS4
    Illustrator = CS5
    etc.
    The Finder will not allow us to make the change to open all of a certain file type in the version we want by default. We also use a third party application that allows us to "double
    click" InDesign files and open them in the correct version. This saves valuable navigation time and because of the OS's problem with using the correct icons, it also saves us time
    dealing with the "Untitled" document when we accidentally convert by opening in the wrong application by mistake. We have gone through Onyx utilities and massive permissions
    troubleshooting to no avail. Does anyone know how to set the default for ALL files of a type for Adobe Apps? This has been thoroughly tested and is not working on 10 plus
    machines, and only effects Adobe apps.
    Any Ideas?

    I think you miss understand the question. There is a problem with OSX 10.6 and Adobe Apps. 10.5 ok, not sure about 10.7 because of all of the other Adobe problems we downgraded the test machine that we used for the upgrade. There is no way that I have found to make the files “Double-Clickable” through assigning a default application of files with Adobe extensions. We already have an app. that we use and it worked fine until 10.6. I can’t just approve a division-wide purchase of software for a bug that may be solvable by other means (by the way supposed cost of the licensing Soxy is deceiving at $20. Not for us. For companies it’s $20 per platform & also for each time Adobe updates. When we swap out hardware, we have to pay $40 again . Their pricing is absurd). $40 x a couple hundred machines every 18 months or so, uugh! The ten or so I’m working with are just the ones in my immediate department.
    I know you have good intentions with your reply and I appreciate it, however I’m looking to solve the problem, not put a band-aid on it. If the problem is by design so Rorohiko can hold companies hostage, then I guess we’ll just have to deal with the few extra clicks it takes to figure out which version we’re in need of, and dragging to the launch bar.
    Thanks very much for your reply,
    Seth

  • No default applications to open items with varied extentsions

    Not being the most technologicaly advanced human here...I repeeatedly am unable to open downloaded files with any extensions other than the basic ones. Right now there are desktop files with .asf, .exe,.wmv extensions that when I try to open them I get the message that "there is no default application specified to open the document "hurl.exe". Is quicktime supposed to handle these files?
    Also, when using Safari, I am unable to import graphics into my clip art gallery in Word AND and PDF download from Safari opens just the first page (Still seemingly in HTML) of the doc with no scroll bar or means tonavigate to any other part of the doc.
    any thoughts out there?
    Thanks!

    I can give some partial answers. Perhaps someone who is more knowledgeable can do a better job.
    I believe that the .exe files are executable files under a Windows operating system. I don't think that you can normally open these in Mac OS X. Perhaps if you had a PC emulator on your computer, you could do that.
    There is some info on .asf files here. It looks like you can open these with Windows Media Player and there is a download site listed for them. Likewise, Windows Media Player evidently will open .wmv files, as discussed here. I have not personally used these types of files or WMP.
    I am confused by your questions regarding Safari. Let's take the case of a PDF file. After it is downloaded, I would expect it to open in Preview unless you have changed something in your preferences. Does that happen? What happens if you double click on the PDF file on your desktop. Does it open normally>
    EMAC G4 1.0 GHz   Mac OS X (10.3.9)  

  • Bug? Wrong default application

    I think I may have found a bug in Tiger related to assigning the correct default application.
    Background:
    Installed TurboTax Deluxe 2005.
    Created a tax return file.
    Exited TurboTax.
    Double clicked tax return file.
    TurboTax Deluxe 2004 is launched and returns an error trying to open the file.
    What I have tried:
    Performed get info on this year's and last year's returns.
    File Type = TaxR; Creator = MIT5 for 2005, MIT4 for 2004
    Dumped Launch services database using lsregister.
    Everything looked OK, found out that Turbo also uses
    an extension of "tax" for the tax return files
    Rebuilt Launch services database using lsregister and problem still existed.
    Added "tax" extension to 2005 tax return file and correct default application chosen.
    Excerpt from Launch Services documentation on how the default application is chosen:
    2. If the document has a filename extension (or if one has been specified as a parameter to LSGetApplicationForInfo), find all applications in the Launch Services database that claim to accept documents with that extension.
    3. If the document carries a four-character file type (or if one has been specified as a parameter), find all applications that claim to accept files of that type.
    4. If more than one application has been found as a result of steps 2–3, apply the following criteria in the order shown:
    a. If the document carries a four-character creator signature (or if one has been specified as a parameter), give preference to any application that claims to accept documents with that signature (typically the application to which the signature belongs).
    Conclusion:
    The correct application is selected when an extension is used, but not when the choice is based on the file type. Therefore, I believe there to be a bug in default application selection base on file type and creator.
    Does anyone see anything place I have gone wrong?
    I know that when I installed TurboTax last year, it worked, so I'm not sure when this bug was born.
    iMac G5 (iSight) Mac OS X (10.4.4)

    When you went to "Get Info," did you try expanding the "open with" section of the window to view the drop-down menu? This drop-down menu under "open with" should tell you which application is set to open the file by default. In that drop-down menu, you should select the newer version of your tax program. Then under "Use this application to open all documents like this," you should probably click the "Change All" button.
    Not sure why the correct application wasn't assigned by OS X in the first place. But I don't know if what you're describing is really a "bug." See if you can set your newer app to be the default application using get info as described. Good luck.
    iBook G4   Mac OS X (10.4.4)  

  • How to specify application by extension rather than mime type (e.g., docx as word, not xml)

    When I try to open a link to a file.docx or file.xlsx, FF sees it as an xml file and wants to open it in my default xml application. I can select Word or Excel (I have Office 2010 installed), but a) it doesn't remember that in the applications list, so I have to browse applications each time, or b) if I set it to always use that type, it tries to open docx in Excel or xlsx in Word, depending on last usage. How can I specify applications by file extension instead of seeing these as the same type of file?
    Thanks,
    Ian
    FF 15.0.1, Win 7, Office 2010

    I don't know if the source server sends the right mime type - it probably doesn't. In fact, now you mention it, I'm not sure I've tried this from any sites except one, which is the one giving me problems. I'll try contacting them about fixing their mime types. Assuming though that they can't or won't fix it, the question still remains - is it possible to set application by extension rather than by mime type?
    Yeah, I can definitely save it and open it, just trying to take the easiest possible route for a quick view.
    Thanks.

  • [Gnome 3] Default application for Calendar

    Hi,
    I have done a fresh install of Arch Linux with Gnome 3 yesterday. I haven't installed evolution, I have installed thunderbird with lighting. But in default applications, Gnome 3 show only gedit like calendar app:
    Is this an Arch bug or Gnome bug?

    thunderbird is not a calendar application unless you tune it up with an extension. therefore it shouldn't be in there
    but if you really want it there,you need to append to /usr/share/applications/thunderbird.desktop, to MimeType, text/calendar;text/x-vcard, then run as root update-desktop-database -q
    Last edited by wonder (2011-10-06 13:50:15)

  • SQL Developer as default for .sql extension

    I specified SQL Developer as the default application for the .sql file extension. When I double click a .sql file, SQL Developer will start up and even open the file but I always receive a Windows error message stating 'Windows cannot find MyFile.sql. Make sure you typed the name correctly and then try again.' I can click okay to the message and the file is open and ready to go in SQL Developer. Is this a problem with my set up or with SQL Developer? Thanks.

    SQL Developer. It has been reported elsewhere

  • How can i change the default application to vlc player for playing any videos on my macbook?

    How can i change the default application to vlc player for playing any videos on my macbook?

    1. Control click the file you want to open.
    2. Click Get Info.
    3. Under open with, pick the App you want to be default.
    4. Click Change All Button.
    5. Confirm your decision.
    You have to do this with every file that has a different extension. You can't change the default for every file with a different extension in a single operation.

  • Xdg (or Gnome 3) default applications

    I want to change the default applications for certain files as determined by xdg, in this case under cinnamon/gnome 3 but I want it to apply across all DEs implementing freedesktop.org standards.
    I have emacs and gvim installed. They both have .desktop files in /usr/share/applications/ which specify their mimetype associations. I happen to have installed emacs after vim, and now I have /usr/share/applications/mimeinfo.cache which seems to be generated from the other files, with lines like, for example:
    text/plain=emacs.desktop;gvim.desktop;
    Which I assume causes emacs to be selected as the default plain text editor (as indeed it is by xdg-mime query default text/plain shows).
    I have three questions:
    1. How can I change the default text editor without editing mimeinfo.cache (I assume it is auto-(re)generated) and without removing emacs' mime types (which are correct and should stay)?
    2. How do I regenerate mimeinfo.cache?
    3. Is there a GUI that allows me to do this stuff (ideally without having to find a file of a particular type to open first - I have tried in Gnome 3: 'System Settings > Details > Default Applications' and there are only a few default 'application types' there, not mime types, and none of them is text editor)?

    With reference to: http://standards.freedesktop.org/deskto … 01s07.html
    In answer to 1:
    It seems the preferences are handled 'externally', and although it doesn't make it clear where it seems to be in /usr/share/applications/defaults.list, I edited min
    [Default Applications]
    x-scheme-handler/spotify=spotify.desktop
    text/plain=gvim.desktop
    (in answer to 2:)
    I then ran 'sudo update-desktop-database'
    And now:
    $ xdg-mime query default text/plain
    gvim.desktop emacs.desktop
    But I'm still interested in the answer to 3, in particular a tool that would change groups of supported mime types and allow you to pick and choose from the lists defined per applications would be useful...

Maybe you are looking for

  • Use dead iMac Display as monitor?

    I have a dead iMac (mobo fried) and was wondering if there is any way I can extract the display panel, and use either a bought or DIY/hacked adapter to use it as a standard monitor.

  • TS3274 cant configure wifi

    I bought my mom a "New iPad" for mother's day and she can't connect to her household wifi right out of the box.  I thought perhaps it was ineptitude on her part so when I visited this weekend I tried myself. I turn it on, it asks me what language to

  • Phone call rings on two different iPhones

    Recently when I receive a call on my i6 phone, my wife's i6 phone will ring with the same caller.  I'm assuming this has to do with sharing but do not know how to correct.

  • PE3 crashes when I click "burn dvd". Any help, please?

    Hello. My PE3 works just fine, except for one problem, that has plagued me for some time. When I finish editing, then complete the menu (title) page, I click "burn dvd". Invariably, PE closes. When I re-open the project and redo the menu- the forced

  • Please help - motion tween + single frame

    ok , so i know how to do motion tween... and i know how to do single frame swap outs (like for a mouth) but i can't do both here is how i have it set up, full body (double click that) head (double click that) face i have the head as single frame so i