Ambient Mime types
  • Paladin of the Pegasos
    Paladin of the Pegasos
    NewSense
    Posts: 1513 from 2012/11/10
    From: Manchester, UK/GB
    This topic isn't so old, and seeing as Barren brought up this interesting topic, I thought I'd ask . . . .

    I'd also like to be able to add a .WMF and .CGM filetypes into MorphOS, as I often need to convert vectored clipart in WMF and CGM format into files that I can use on MorphOS directly, such as, ILBM/IFF, BMP, etc which I like to convert using Metaview v2.9, which is usually quite stable under MorphOS 68k emulation.

    I have managed to add the .DR2D filetype into MorphOS MIME prefs as it is recognised as .X-IFF filetype, which is already part of MorphOS Ambient MIME types, and can be set quite simply to open directly with a right-click on the file - choosing open with - Metaview.

    Can someone give clear instructions on how to create a new filetype, if this is possible, so I can adapt MorphOS to suit my needs. 8-)
    MacMini 1.5GHz,64MB VRAM, PowerBooks A1138/9 (Model 5,8/9),PowerMac G5 2.3GHz(DP), iMac A1145 2.1GHz 20", all with MorphOS v3.18+,Airport,Bluetooth,A1016 Keyboard,T-RB22 Mouse,DVD-RW-DL,MiniMax,Firewire/USB2 & MacOSX 10.4/5
  • »28.02.17 - 01:16
    Profile
  • jPV
  • Yokemate of Keyboards
    Yokemate of Keyboards
    jPV
    Posts: 2096 from 2003/2/24
    From: po-RNO
    Quote:

    NewSense wrote:
    Can someone give clear instructions on how to create a new filetype, if this is possible, so I can adapt MorphOS to suit my needs. 8-)


    Here is how I'd do it:

    1) First open the http://www.iana.org/assignments/media-types/ page (as suggested in the SYS:MorphOS/Ambient/recognition.db file), and look for the wanted media type.

    2) We can find wmf there, and it seems to be categorized as image/wmf, let's click the "image/wmf" link in the second column on the page to get more information. We see its full name "Windows Metafile Format", extension .wmf (naturally), and magic numbers (D7 CD C6 9A), which is extremely useful info. Now we know all we need to know and can create a new filetype.

    3) Ambient's filetype directory has the same hierarchy with the standard media type categories, so we can place our wmf filetype into the image directory. Let's create a new file there, for example from the shell: Ed SYS:Prefs/Ambient/filetypes/image/wmf

    4) Type in the standard headers which all filetypes should contain:
    Code:
    AMTD
    1

    Then the type line (we got the type in step 2):
    Code:
    Type image/wmf

    And the name we also got in step 2:
    Code:
    Name Windows Metafile Format

    Then start the match block, which defines how the file is recognized:
    Code:
    Match

    Let's add the pattern hint rule with the extension we know:
    Code:
    PatternHint #?.wmf

    And then the actual matching rule. We got the magic numbers in the step 2 and they indicate the hex numbers found from the beginning of each wmf file. We tell Ambient to look for those numbers to make the recognition. $ tells the searching will be done in hex format.
    Code:
    Match $D7CDC69A

    Now we can end the match block:
    Code:
    End

    We also need another End to end the whole filetype definition:
    Code:
    End


    You can also make the inner blocks intented to make it look cleaner, here's the whole filetype definition:
    Code:
    AMTD
    1
    Type image/wmf
    Name Windows Metafile Format
    Match
    PatternHint #?.wmf
    Match $D7CDC69A
    End
    End


    5) Save the file and we're done. You can now open the Ambient MIME type settings and add new actions for the new filetype there.


    Let's try the same for CGM then. The page in the step 1 tells us that its name is "Computer Graphics Metafile" and it's type is "image/cgm". Unfortunately it doesn't seem to tell more about the recognition, and a quick googling reveals that files may contain the string "BegMF", but not always.

    We have to create a rule which will work even if that string isn't found, I think we have to fallback to filename based recognitioning in this case. So, let's create a rule which first tries to match the string (add "s" in front of it to indicate it's a plain text string instead of hex or so) or if it's not found then to filename:
    Code:
    Match sBegMF
    OR
    Name #?.cgm

    You could also match only to name, but it's more elegant to match the contents when you can.

    Full filetype for the cgm would be like this then:
    Code:
    AMTD
    1
    Type image/cgm
    Name Computer Graphics Metafile
    Match
    PatternHint #?.cgm
    Match sBegMF
    OR
    Name #?.cgm
    End
    End
  • »28.02.17 - 07:03
    Profile Visit Website
  • Paladin of the Pegasos
    Paladin of the Pegasos
    NewSense
    Posts: 1513 from 2012/11/10
    From: Manchester, UK/GB
    Thanks jPV for those instructions - THEY WORK, well at least for me, that is. . . . once I had rebooted the system, as the filetypes seem to be read-in at boot-up, and not if they are changed after that. Anyway, once I had adjusted the Ambient MIME types 'action' with Metaview as my chosen program to open the filetype then both the WMF and CGM files opened Metaview when double-clicked on, so I am very grateful to you for your little workshop in adjusting/editing/defining MIME/Filetypes in MorphOS.8-D

    Maybe you should add that 'lesson' into the library you are building 'all by yourself' on such features for MorphOS. 8-)

    I have not forgotten about RNO info issues we discussed and I will let you have more feedback on that shortly.;-)
    MacMini 1.5GHz,64MB VRAM, PowerBooks A1138/9 (Model 5,8/9),PowerMac G5 2.3GHz(DP), iMac A1145 2.1GHz 20", all with MorphOS v3.18+,Airport,Bluetooth,A1016 Keyboard,T-RB22 Mouse,DVD-RW-DL,MiniMax,Firewire/USB2 & MacOSX 10.4/5
  • »28.02.17 - 20:11
    Profile
  • Just looking around
    Posts: 20 from 2017/3/16
    When I click on a pdf file the mime type for it automatically ensures that it opens via vpdf, because the mime type command reads vpdf %sp.

    I am trying to do something similar for ghostscript, but have so far failed. The longwinded way which does work perfectly is as follows:

    Place the relevant file, called file.ps say, into ram. Launch ghostscript via sys:applications/ghostscript/bin/gs. This brings up the gs window into which I next type (ram:file.ps) run Everything works fine then.

    My question is how to implement that through a ps mime type? What commands do I need to enter? The problem seems to be the brackets surrounding the filename and the extra run command. Does anyone know the solution or correct syntax?

    RD
    ---------

    Quote:

    NewSense wrote:
    Quote:

    Barren wrote: Perhaps I have just the bad habit to instinctively press return when I reach the end of the line. Ohhhh soooo soorrry I will try to avoid that.

    I am not 'having a go' at you, I would just have thought you already knew that word-wrap is enabled when you type into the input editor. However, as you'd more recently come from an Amiga background, as many of us have, then you might have written the text on your Amiga and transferred it here, and it had imported the incorrect word-wrap that often is associated with some of the Classic Amiga editors. That's obviously not the case so it's more a heads-up in this case. :-)

    Quote:

    Barren wrote: how can I setup a mime type for dos scripts properly, and how can I set up mime types for MOS elf executables and amiga os 68K ones, even just to associate different icons. I bet it's impossible.

    I am not sure what you are trying to achieve with a DOS script, but you may want to take a look at the MorphOS Library for more inspiration or wait a little longer for any of the developers to come along with more guidance.

    I should say that if you have a MOS executable then the system should recognise that automatically, and the same for 68k executables, but obviously some 68k executables, such as games that 'hit the hardware' may only run within an Amiga Emulator, though many applications run through 'Trance' without issues.

    You could also have a read through the MorphOS Library, in particular:

    Getting Started - then scroll or search to the part on - Open PDF Files Automatically, and take a look at the associated screenshot, just below, which may give you an idea of what you want to do.

    Though it's probably as easy to select from the right-click menu Settings > Ambient > MIME and then choose 'text' or 'internal' and click the [+] to expand each of those options list to see other files and how they work, and see if there is a suggestion there to prompt you to work out what you are trying to achieve. :-o
  • »26.05.17 - 00:39
    Profile
  • jPV
  • Yokemate of Keyboards
    Yokemate of Keyboards
    jPV
    Posts: 2096 from 2003/2/24
    From: po-RNO
    Quote:

    Robdel wrote:
    When I click on a pdf file the mime type for it automatically ensures that it opens via vpdf, because the mime type command reads vpdf %sp.

    I am trying to do something similar for ghostscript, but have so far failed. The longwinded way which does work perfectly is as follows:

    Place the relevant file, called file.ps say, into ram. Launch ghostscript via sys:applications/ghostscript/bin/gs. This brings up the gs window into which I next type (ram:file.ps) run Everything works fine then.

    My question is how to implement that through a ps mime type? What commands do I need to enter? The problem seems to be the brackets surrounding the filename and the extra run command. Does anyone know the solution or correct syntax?



    If you try to launch "gs:bin/gs -h" in the shell (or with -help or --help argument), you get a description of the command line arguments. It appears that you don't need to use brackets when giving a file as an argument, so simple "gs:bin/gs ram:file.ps" will work.

    Also if you want that program quits automatically after viewing a file and want to disable the text output to see just the graphical output, I'd use this kind of line in the mime settings for the already existing postscript mimetype:
    Run >NIL: gs:bin/gs -dBATCH -dNOPAUSE %sp


    [ Edited by jPV 26.05.2017 - 16:27 ]
  • »26.05.17 - 13:23
    Profile Visit Website
  • Just looking around
    Posts: 20 from 2017/3/16
    Thank you very much for your suggestion. It works well. This is a good example of why forums are useful.



    quote]jPV wrote:
    Quote:

    Robdel wrote:
    When I click on a pdf file the mime type for it automatically ensures that it opens via vpdf, because the mime type command reads vpdf %sp.

    I am trying to do something similar for ghostscript, but have so far failed. The longwinded way which does work perfectly is as follows:

    Place the relevant file, called file.ps say, into ram. Launch ghostscript via sys:applications/ghostscript/bin/gs. This brings up the gs window into which I next type (ram:file.ps) run Everything works fine then.

    My question is how to implement that through a ps mime type? What commands do I need to enter? The problem seems to be the brackets surrounding the filename and the extra run command. Does anyone know the solution or correct syntax?



    If you try to launch "gs:bin/gs -h" in the shell (or with -help or --help argument), you get a description of the command line arguments. It appears that you don't need to use brackets when giving a file as an argument, so simple "gs:bin/gs ram:file.ps" will work.

    Also if you want that program quits automatically after viewing a file and want to disable the text output to see just the graphical output, I'd use this kind of line in the mime settings for the already existing postscript mimetype:
    Run >NIL: gs:bin/gs -dBATCH -dNOPAUSE %sp

  • »27.05.17 - 06:12
    Profile

  •