Matlab .desktop file












6















(This is not about creating a launcher in the dock or anything like that.)



When I navigate into a folder with some Matlab .m files, and simply do



matlab myscript.m


in the terminal, it launches Matlab with working directory set to where the file is.



This has some perks: If there is also a startup.m file in the directory - and therefore in Matlab path - Matlab will notice and run it.



I tried to replicate this functionality with a .desktop file, so I could click an .m file (recognized as objective C by Ubuntu...) with the same results as if I run it from terminal, but no luck.



Here is what I have tried:



I put text/x-objcsrc=Matlab.desktop in /home/jakub/.local/share/applications/mimeapps.list



and created this desktop file in /home/jakub/.local/share/applications



Version=1.0
Type=Application
Terminal=false
Exec=matlab -desktop
Name=Matlab
Icon=/home/jakub/Pictures/icons/Apps-Matlab-icon.png
Categories=Development


When I click an .m file, it launches Matlab, but it is not equivalent to running it from the terminal (see above): Mainly, work dir is set to Matlab's default, instead of where the script is, and the script does not open, just plain Matlab with empty editor.



I also tried this:



Exec=matlab -desktop -r "edit %f"


which opens the file but does not set the work dir



Exec=matlab -desktop -r "cd %d"


which changes the work dir, but after Matlab is run, which means it will not run the code in startup.m (so it is not equivalent to doing matlab myscript.m in the terminal).



Is there any way of perfectly mimicking matlab myscript.m as run from the terminal, but in a desktop file?










share|improve this question



























    6















    (This is not about creating a launcher in the dock or anything like that.)



    When I navigate into a folder with some Matlab .m files, and simply do



    matlab myscript.m


    in the terminal, it launches Matlab with working directory set to where the file is.



    This has some perks: If there is also a startup.m file in the directory - and therefore in Matlab path - Matlab will notice and run it.



    I tried to replicate this functionality with a .desktop file, so I could click an .m file (recognized as objective C by Ubuntu...) with the same results as if I run it from terminal, but no luck.



    Here is what I have tried:



    I put text/x-objcsrc=Matlab.desktop in /home/jakub/.local/share/applications/mimeapps.list



    and created this desktop file in /home/jakub/.local/share/applications



    Version=1.0
    Type=Application
    Terminal=false
    Exec=matlab -desktop
    Name=Matlab
    Icon=/home/jakub/Pictures/icons/Apps-Matlab-icon.png
    Categories=Development


    When I click an .m file, it launches Matlab, but it is not equivalent to running it from the terminal (see above): Mainly, work dir is set to Matlab's default, instead of where the script is, and the script does not open, just plain Matlab with empty editor.



    I also tried this:



    Exec=matlab -desktop -r "edit %f"


    which opens the file but does not set the work dir



    Exec=matlab -desktop -r "cd %d"


    which changes the work dir, but after Matlab is run, which means it will not run the code in startup.m (so it is not equivalent to doing matlab myscript.m in the terminal).



    Is there any way of perfectly mimicking matlab myscript.m as run from the terminal, but in a desktop file?










    share|improve this question

























      6












      6








      6








      (This is not about creating a launcher in the dock or anything like that.)



      When I navigate into a folder with some Matlab .m files, and simply do



      matlab myscript.m


      in the terminal, it launches Matlab with working directory set to where the file is.



      This has some perks: If there is also a startup.m file in the directory - and therefore in Matlab path - Matlab will notice and run it.



      I tried to replicate this functionality with a .desktop file, so I could click an .m file (recognized as objective C by Ubuntu...) with the same results as if I run it from terminal, but no luck.



      Here is what I have tried:



      I put text/x-objcsrc=Matlab.desktop in /home/jakub/.local/share/applications/mimeapps.list



      and created this desktop file in /home/jakub/.local/share/applications



      Version=1.0
      Type=Application
      Terminal=false
      Exec=matlab -desktop
      Name=Matlab
      Icon=/home/jakub/Pictures/icons/Apps-Matlab-icon.png
      Categories=Development


      When I click an .m file, it launches Matlab, but it is not equivalent to running it from the terminal (see above): Mainly, work dir is set to Matlab's default, instead of where the script is, and the script does not open, just plain Matlab with empty editor.



      I also tried this:



      Exec=matlab -desktop -r "edit %f"


      which opens the file but does not set the work dir



      Exec=matlab -desktop -r "cd %d"


      which changes the work dir, but after Matlab is run, which means it will not run the code in startup.m (so it is not equivalent to doing matlab myscript.m in the terminal).



      Is there any way of perfectly mimicking matlab myscript.m as run from the terminal, but in a desktop file?










      share|improve this question














      (This is not about creating a launcher in the dock or anything like that.)



      When I navigate into a folder with some Matlab .m files, and simply do



      matlab myscript.m


      in the terminal, it launches Matlab with working directory set to where the file is.



      This has some perks: If there is also a startup.m file in the directory - and therefore in Matlab path - Matlab will notice and run it.



      I tried to replicate this functionality with a .desktop file, so I could click an .m file (recognized as objective C by Ubuntu...) with the same results as if I run it from terminal, but no luck.



      Here is what I have tried:



      I put text/x-objcsrc=Matlab.desktop in /home/jakub/.local/share/applications/mimeapps.list



      and created this desktop file in /home/jakub/.local/share/applications



      Version=1.0
      Type=Application
      Terminal=false
      Exec=matlab -desktop
      Name=Matlab
      Icon=/home/jakub/Pictures/icons/Apps-Matlab-icon.png
      Categories=Development


      When I click an .m file, it launches Matlab, but it is not equivalent to running it from the terminal (see above): Mainly, work dir is set to Matlab's default, instead of where the script is, and the script does not open, just plain Matlab with empty editor.



      I also tried this:



      Exec=matlab -desktop -r "edit %f"


      which opens the file but does not set the work dir



      Exec=matlab -desktop -r "cd %d"


      which changes the work dir, but after Matlab is run, which means it will not run the code in startup.m (so it is not equivalent to doing matlab myscript.m in the terminal).



      Is there any way of perfectly mimicking matlab myscript.m as run from the terminal, but in a desktop file?







      .desktop matlab






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 6 '16 at 15:08









      jakubjakub

      1312




      1312






















          2 Answers
          2






          active

          oldest

          votes


















          3














          I had the a similar issue, when I tried to set Matlab up manually.


          Eventually, I ran:
          sudo apt-get install matlab-support

          and followed installation instructions. This just adds Matlab to the Dashboard.


          The resulting matlab.desktop file reads:



          [Desktop Entry]
          Version=1.0
          Type=Application
          Terminal=false
          Exec=matlab -desktop
          Name=MATLAB
          Icon=/usr/share/icons/hicolor/48x48/apps/matlab.png
          Categories=Development;Math;Science
          Comment=Scientific computing environment
          StartupNotify=true
          StartupWMClass=com-mathworks-util-PostVMInit


          To open .m files in matlab by clicking on them I used the Ubuntu GUI to set it to open those files with the command:



          matlab -desktop -r "open %U;"


          This both opens the file in Matlab and sets the current working directory to where the file is located (at least with Matlab 2016b).



          I hope this information helps.






          share|improve this answer

































            -1














            A naive answer: have you tried



            Exec=bash matlab %f


            In principle, this should be equivalent to you running it on the shell with the file as argument.






            share|improve this answer
























            • Seems logical, but does not work. Neither bash matlab %f or bash matlab -desktop %f seems to do anything. When providing a full path to Matlab executable (instead of just matlab) Matlab launches, and in htop, I can see a lot of lines saying /usr/path/to/matlab -desktop /home/path/to/myscript.m but the result is the same - opened with the default working dir and does not open the script in the editor. So it is still not equivalent to launching it from the terminal.

              – jakub
              Sep 7 '16 at 9:31











            • Sorry I could not be of more help. I am curious on the solution as I am a frequent Matlab user and see the potential of what you are looking to accomplish.

              – Juan Antonio
              Sep 8 '16 at 0:38











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f821721%2fmatlab-desktop-file%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            I had the a similar issue, when I tried to set Matlab up manually.


            Eventually, I ran:
            sudo apt-get install matlab-support

            and followed installation instructions. This just adds Matlab to the Dashboard.


            The resulting matlab.desktop file reads:



            [Desktop Entry]
            Version=1.0
            Type=Application
            Terminal=false
            Exec=matlab -desktop
            Name=MATLAB
            Icon=/usr/share/icons/hicolor/48x48/apps/matlab.png
            Categories=Development;Math;Science
            Comment=Scientific computing environment
            StartupNotify=true
            StartupWMClass=com-mathworks-util-PostVMInit


            To open .m files in matlab by clicking on them I used the Ubuntu GUI to set it to open those files with the command:



            matlab -desktop -r "open %U;"


            This both opens the file in Matlab and sets the current working directory to where the file is located (at least with Matlab 2016b).



            I hope this information helps.






            share|improve this answer






























              3














              I had the a similar issue, when I tried to set Matlab up manually.


              Eventually, I ran:
              sudo apt-get install matlab-support

              and followed installation instructions. This just adds Matlab to the Dashboard.


              The resulting matlab.desktop file reads:



              [Desktop Entry]
              Version=1.0
              Type=Application
              Terminal=false
              Exec=matlab -desktop
              Name=MATLAB
              Icon=/usr/share/icons/hicolor/48x48/apps/matlab.png
              Categories=Development;Math;Science
              Comment=Scientific computing environment
              StartupNotify=true
              StartupWMClass=com-mathworks-util-PostVMInit


              To open .m files in matlab by clicking on them I used the Ubuntu GUI to set it to open those files with the command:



              matlab -desktop -r "open %U;"


              This both opens the file in Matlab and sets the current working directory to where the file is located (at least with Matlab 2016b).



              I hope this information helps.






              share|improve this answer




























                3












                3








                3







                I had the a similar issue, when I tried to set Matlab up manually.


                Eventually, I ran:
                sudo apt-get install matlab-support

                and followed installation instructions. This just adds Matlab to the Dashboard.


                The resulting matlab.desktop file reads:



                [Desktop Entry]
                Version=1.0
                Type=Application
                Terminal=false
                Exec=matlab -desktop
                Name=MATLAB
                Icon=/usr/share/icons/hicolor/48x48/apps/matlab.png
                Categories=Development;Math;Science
                Comment=Scientific computing environment
                StartupNotify=true
                StartupWMClass=com-mathworks-util-PostVMInit


                To open .m files in matlab by clicking on them I used the Ubuntu GUI to set it to open those files with the command:



                matlab -desktop -r "open %U;"


                This both opens the file in Matlab and sets the current working directory to where the file is located (at least with Matlab 2016b).



                I hope this information helps.






                share|improve this answer















                I had the a similar issue, when I tried to set Matlab up manually.


                Eventually, I ran:
                sudo apt-get install matlab-support

                and followed installation instructions. This just adds Matlab to the Dashboard.


                The resulting matlab.desktop file reads:



                [Desktop Entry]
                Version=1.0
                Type=Application
                Terminal=false
                Exec=matlab -desktop
                Name=MATLAB
                Icon=/usr/share/icons/hicolor/48x48/apps/matlab.png
                Categories=Development;Math;Science
                Comment=Scientific computing environment
                StartupNotify=true
                StartupWMClass=com-mathworks-util-PostVMInit


                To open .m files in matlab by clicking on them I used the Ubuntu GUI to set it to open those files with the command:



                matlab -desktop -r "open %U;"


                This both opens the file in Matlab and sets the current working directory to where the file is located (at least with Matlab 2016b).



                I hope this information helps.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 22 at 4:27









                Jonas Stein

                127110




                127110










                answered Dec 26 '16 at 8:13









                yaron160yaron160

                301128




                301128

























                    -1














                    A naive answer: have you tried



                    Exec=bash matlab %f


                    In principle, this should be equivalent to you running it on the shell with the file as argument.






                    share|improve this answer
























                    • Seems logical, but does not work. Neither bash matlab %f or bash matlab -desktop %f seems to do anything. When providing a full path to Matlab executable (instead of just matlab) Matlab launches, and in htop, I can see a lot of lines saying /usr/path/to/matlab -desktop /home/path/to/myscript.m but the result is the same - opened with the default working dir and does not open the script in the editor. So it is still not equivalent to launching it from the terminal.

                      – jakub
                      Sep 7 '16 at 9:31











                    • Sorry I could not be of more help. I am curious on the solution as I am a frequent Matlab user and see the potential of what you are looking to accomplish.

                      – Juan Antonio
                      Sep 8 '16 at 0:38
















                    -1














                    A naive answer: have you tried



                    Exec=bash matlab %f


                    In principle, this should be equivalent to you running it on the shell with the file as argument.






                    share|improve this answer
























                    • Seems logical, but does not work. Neither bash matlab %f or bash matlab -desktop %f seems to do anything. When providing a full path to Matlab executable (instead of just matlab) Matlab launches, and in htop, I can see a lot of lines saying /usr/path/to/matlab -desktop /home/path/to/myscript.m but the result is the same - opened with the default working dir and does not open the script in the editor. So it is still not equivalent to launching it from the terminal.

                      – jakub
                      Sep 7 '16 at 9:31











                    • Sorry I could not be of more help. I am curious on the solution as I am a frequent Matlab user and see the potential of what you are looking to accomplish.

                      – Juan Antonio
                      Sep 8 '16 at 0:38














                    -1












                    -1








                    -1







                    A naive answer: have you tried



                    Exec=bash matlab %f


                    In principle, this should be equivalent to you running it on the shell with the file as argument.






                    share|improve this answer













                    A naive answer: have you tried



                    Exec=bash matlab %f


                    In principle, this should be equivalent to you running it on the shell with the file as argument.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 6 '16 at 15:59









                    Juan AntonioJuan Antonio

                    8461626




                    8461626













                    • Seems logical, but does not work. Neither bash matlab %f or bash matlab -desktop %f seems to do anything. When providing a full path to Matlab executable (instead of just matlab) Matlab launches, and in htop, I can see a lot of lines saying /usr/path/to/matlab -desktop /home/path/to/myscript.m but the result is the same - opened with the default working dir and does not open the script in the editor. So it is still not equivalent to launching it from the terminal.

                      – jakub
                      Sep 7 '16 at 9:31











                    • Sorry I could not be of more help. I am curious on the solution as I am a frequent Matlab user and see the potential of what you are looking to accomplish.

                      – Juan Antonio
                      Sep 8 '16 at 0:38



















                    • Seems logical, but does not work. Neither bash matlab %f or bash matlab -desktop %f seems to do anything. When providing a full path to Matlab executable (instead of just matlab) Matlab launches, and in htop, I can see a lot of lines saying /usr/path/to/matlab -desktop /home/path/to/myscript.m but the result is the same - opened with the default working dir and does not open the script in the editor. So it is still not equivalent to launching it from the terminal.

                      – jakub
                      Sep 7 '16 at 9:31











                    • Sorry I could not be of more help. I am curious on the solution as I am a frequent Matlab user and see the potential of what you are looking to accomplish.

                      – Juan Antonio
                      Sep 8 '16 at 0:38

















                    Seems logical, but does not work. Neither bash matlab %f or bash matlab -desktop %f seems to do anything. When providing a full path to Matlab executable (instead of just matlab) Matlab launches, and in htop, I can see a lot of lines saying /usr/path/to/matlab -desktop /home/path/to/myscript.m but the result is the same - opened with the default working dir and does not open the script in the editor. So it is still not equivalent to launching it from the terminal.

                    – jakub
                    Sep 7 '16 at 9:31





                    Seems logical, but does not work. Neither bash matlab %f or bash matlab -desktop %f seems to do anything. When providing a full path to Matlab executable (instead of just matlab) Matlab launches, and in htop, I can see a lot of lines saying /usr/path/to/matlab -desktop /home/path/to/myscript.m but the result is the same - opened with the default working dir and does not open the script in the editor. So it is still not equivalent to launching it from the terminal.

                    – jakub
                    Sep 7 '16 at 9:31













                    Sorry I could not be of more help. I am curious on the solution as I am a frequent Matlab user and see the potential of what you are looking to accomplish.

                    – Juan Antonio
                    Sep 8 '16 at 0:38





                    Sorry I could not be of more help. I am curious on the solution as I am a frequent Matlab user and see the potential of what you are looking to accomplish.

                    – Juan Antonio
                    Sep 8 '16 at 0:38


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f821721%2fmatlab-desktop-file%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Human spaceflight

                    Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

                    張江高科駅