HISE Logo Forum
    • Categories
    • Register
    • Login

    File.move to user library on a Mac - help!

    Scheduled Pinned Locked Moved Scripting
    20 Posts 6 Posters 786 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      tomekslesicki
      last edited by

      I'm getting some serious inconsistency with the File.move command when moving files to the user library folder on macOS. Whenever I test it - whether in HISE or in a built standalone app - the command works properly. I'm getting some reports from users about the files not being copied over. My script looks like this:

      // Check if file exists and remove it if it does
      if (componentFileMac.isFile() || componentFileMac.isDirectory())
      {
          componentFileMac.deleteFileOrDirectory();
      }
      
      workingFolder.getChildFile(pluginname + ".component").move(componentFileMac);
      

      All vars used are defined properly and again, it works on macOS 12.4 and above. I guess the issues is with some older macOS version, but I'm yet to confirm that. Anyway - is there something about using the .move command to get the files to the user library I should know about? Clearly, it's a permissions issue. Is the .copy method safer? What's the smart way about it?

      As a walkaround I could start a .pkg from the main script just to get the files in place, but it's a custom installer and I think it would be great to keep the experience consistent without running yet another app from the main app.

      d.healeyD ustkU 2 Replies Last reply Reply Quote 0
      • d.healeyD
        d.healey @tomekslesicki
        last edited by

        @tomekslesicki I haven't ran into any issues with it but the JUCE documentation says that the move function can fail so it can be better to copy the file and delete the original if the copy is successful.

        Link Preview Image
        JUCE: File Class Reference

        favicon

        (docs.juce.com)

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        1 Reply Last reply Reply Quote 0
        • ustkU
          ustk @tomekslesicki
          last edited by

          @tomekslesicki @d-healey Wouldn't it be safer to use a background task with a shell command anyway? Seems asking for troubles to do this from Hise/exported binary... @aaronventure seems to master this bit...

          Can't help pressing F5 in the forum...

          A d.healeyD 2 Replies Last reply Reply Quote 1
          • A
            aaronventure @ustk
            last edited by

            @ustk BackgroundTask is a great fallback option when the JUCE/HISE stuff seems to be inadequate for the job, but David's making a lot of sense in his post, too.

            T 1 Reply Last reply Reply Quote 0
            • T
              tomekslesicki @aaronventure
              last edited by tomekslesicki

              @aaronventure @ustk @d-healey thank you!

              @ustk could you please give me an example of the background task running a shell script so I can test this?

              A 1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey @ustk
                last edited by

                @ustk said in File.move to user library on a Mac - help!:

                Wouldn't it be safer to use a background task

                Well I haven't ran into any issues with it, however in a recent update in Rhapsody I've put the move file stuff into a background task (no shell script), but not because it was failing, but because it was holding up my GUI.

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

                1 Reply Last reply Reply Quote 0
                • A
                  aaronventure @tomekslesicki
                  last edited by

                  @tomekslesicki https://docs.hise.dev/scripting/scripting-api/backgroundtask/index.html#runprocess

                  You can drop an entire script as a string as an argument into runProcess. Just pretend you're calling the script from a terminal. ChatGPT can help you here a lot.

                  Keep in mind that you'll need different variations of the runProcess function for Windows and macOS, as you'll use PowerShell on Windows and probably bash on macOS.

                  T 1 Reply Last reply Reply Quote 0
                  • T
                    tomekslesicki @aaronventure
                    last edited by

                    @aaronventure I already have a working shell script from the pkg installer I had earlier, so I could definitely reuse that. I'm totally new to background tasks, though. Could you please help me out to understand what I should pass into the docs example? Thank you!

                    A 1 Reply Last reply Reply Quote 0
                    • A
                      aaronventure @tomekslesicki
                      last edited by

                      @tomekslesicki BackgroundTask.runProcess(var command, var args, var logFunction)

                      the command is the string of a command, like "bash", and args are any args that would follow a terminal command.

                      Inyour case

                      const scriptStr = "myScript";
                      
                      BackgroundTask.runProcess("bash", ["-c", scriptStr], function(thread, isFinished, data)
                      {
                          // Function body
                      });
                      

                      The function will execute every time the terminal would output something, as well as once more on isFinished == 1. Data is the the terminal output string.

                      Be careful regarding escaping for new lines, paths etc. It'll take some trial and error.

                      Try the docs example in an empty project and try with very simple stuff like making curl calls to a test API endpoint, or just calling help commands for an app, etc.

                      T 1 Reply Last reply Reply Quote 0
                      • T
                        tomekslesicki @aaronventure
                        last edited by

                        @aaronventure Perfect, thanks so much!

                        griffinboyG 1 Reply Last reply Reply Quote 0
                        • griffinboyG
                          griffinboy @tomekslesicki
                          last edited by

                          @tomekslesicki

                          Congrats on launching the new installer system

                          T 1 Reply Last reply Reply Quote 0
                          • T
                            tomekslesicki @griffinboy
                            last edited by

                            @griffinboy thank you!

                            Christoph HartC 1 Reply Last reply Reply Quote 1
                            • Christoph HartC
                              Christoph Hart @tomekslesicki
                              last edited by

                              @tomekslesicki kind of unrelated, but I realized an issue with file permissions on macOS that I wasn't aware of and this also might be the reason for why the move operation fails with your users:

                              usually you would expect that the user has read & write access to its user app data directory. However if you create the app data folder during your installation routine while having elevated admin privileges, it will inherit the user rights and treat it as a folder outside the user domain. This will lead to all subsequent read & write operations to that folder to fail which is super catastrophic as it will not store the link file, settings or license files.

                              We ran into that issue a few days ago when beta testing an update and it turns out that our installer created these folders after copying the plugin files to the global plugin folder (which requires admin privileges, hence the entire script ran with elevated privileges).

                              I could reproduce this very easily with a non-admin account, but other beta testers even experienced that issue with an admin account, which sounds super fishy...

                              T 1 Reply Last reply Reply Quote 2
                              • T
                                tomekslesicki @Christoph Hart
                                last edited by

                                @Christoph-Hart from what I see, File.createDirectory() creates read-only folders, even if the parent folder is set to read & write. At least on Windows.

                                d.healeyD 1 Reply Last reply Reply Quote 0
                                • d.healeyD
                                  d.healey @tomekslesicki
                                  last edited by

                                  @tomekslesicki said in File.move to user library on a Mac - help!:

                                  File.createDirectory() creates read-only folders

                                  Not here. But you could always call this after

                                  fb42dd7c-d60e-4945-a63e-0f25bf9826a1-image.png

                                  Libre Wave - Freedom respecting instruments and effects
                                  My Patreon - HISE tutorials
                                  YouTube Channel - Public HISE tutorials

                                  T 1 Reply Last reply Reply Quote 0
                                  • T
                                    tomekslesicki @d.healey
                                    last edited by

                                    @d-healey thank you, but this doesn't seem to work when I test it. Shoud it be (false, false) or (fase, true)?

                                    d.healeyD 1 Reply Last reply Reply Quote 0
                                    • d.healeyD
                                      d.healey @tomekslesicki
                                      last edited by

                                      @tomekslesicki Either, depends on if you want it to apply to all sub-folders.

                                      Libre Wave - Freedom respecting instruments and effects
                                      My Patreon - HISE tutorials
                                      YouTube Channel - Public HISE tutorials

                                      T 1 Reply Last reply Reply Quote 0
                                      • T
                                        tomekslesicki @d.healey
                                        last edited by

                                        @d-healey that's what I thought. The 2nd true will mean that subfolders are supposed to be affected, too, right?

                                        d.healeyD 1 Reply Last reply Reply Quote 0
                                        • d.healeyD
                                          d.healey @tomekslesicki
                                          last edited by

                                          @tomekslesicki Yes

                                          Libre Wave - Freedom respecting instruments and effects
                                          My Patreon - HISE tutorials
                                          YouTube Channel - Public HISE tutorials

                                          T 1 Reply Last reply Reply Quote 0
                                          • T
                                            tomekslesicki @d.healey
                                            last edited by

                                            @d-healey thank you!

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            53

                                            Online

                                            1.7k

                                            Users

                                            11.7k

                                            Topics

                                            101.8k

                                            Posts