12 Replies Latest reply on May 1, 2007 3:53 PM by Charles Simonson

    Copy/Save file to flash drive

    Charles Simonson
      I am trying to create a script where the user can initiate a download/Save/copy of a stored file from my HDD to a flash drive. It would seem that baCopyProgressFile would be ideal for this situation, but I am authoring on a Intel MBP and it does not appear that Buddy API is compatible with Intel Macs at this time. I only need this projector to display on this MBP (this is really just a quick proof of concept project that will be run locally), so any suggestions or alternatives would be very helpful. Thanks.

        • 1. Re: Copy/Save file to flash drive
          Level 7
          > on mouseUp me
          > OK = baCopyFileProgress("Mac OS X:Users/user/Desktop/bb/480p.mov",
          > "/Volumes/bb/480p.mov","IfNewer", "Backing up files... ", "Cancel", 0 )
          alert OK
          > end

          If you add the 'alert' (as I have above), what does it tell you?
          Also, you seem to be mixing Posix-style paths (/) and old-style Mac
          folder delimiters (:) and this doesn't seem like a good idea. Stick with
          one or the other, but try not to mix them.
          • 2. Re: Copy/Save file to flash drive
            Charles Simonson Level 1
            quote:

            If you add the 'alert' (as I have above), what does it tell you?

            I get an error message on playback of the movie with the following statement:

            Script Error: Handler not defined
            (code of the script)

            #baCopyFileProgress


            quote:

            Also, you seem to be mixing Posix-style paths (/) and old-style Mac
            folder delimiters (:) and this doesn't seem like a good idea.


            I didn't start out that way, but I changed it when I ran into some other examples of the baCopyFile's usage. In any case, I did change it and still no luck.


            • 3. Re: Copy/Save file to flash drive
              Level 7

              > Script Error: Handler not defined
              >
              > #baCopyFileProgress

              That message almost always means that you do not have BuddyAPI installed
              correctly. You need to download the xtra from www.mods.com.au/budapi
              then install it into your xtras folder for Director - typically your
              xtras folder is like this:

              Hard drive:Applications:Macromedia Director MX 2004:Configuration:Xtras

              Then open Director and if your code is correct, it should work.
              • 4. Re: Copy/Save file to flash drive
                Charles Simonson Level 1
                Well, it looks like it was a bad installation. The files that I downloaded were in there, but for some reason the package I downloaded was incomplete. I went to my G5 machine and copied the files over to my MBP, and at least the script is recognized.

                But now, when I play the movie inside Director, and initiate the action to copy the file, nothing happens. If I build the projector, then I get a "script error" message. Anyone have any thoughts on that?

                Thanks for your help thus far.
                • 5. Re: Copy/Save file to flash drive
                  Level 7
                  > But now, when I play the movie inside Director, and initiate the action to
                  > copy the file, nothing happens.

                  What does the 'alert' I added tell you?

                  > If I build the projector, then I get a "script
                  > error" message. Anyone have any thoughts on that?

                  As well as having the xtra available during authoring, you also need it
                  available to your projector. Either use the Modify -> Movie -> Xtras
                  dialog to include it in the projector, or create a folder alongside your
                  projector named "xtras" and place a copy in there.
                  • 6. Copy/Save file to flash drive
                    Charles Simonson Level 1
                    quote:

                    Originally posted by: Newsgroup User
                    What does the 'alert' I added tell you?

                    It now tells me "Script error: Variable used before assigned value Alert OK ?"


                    quote:

                    Originally posted by: Newsgroup User
                    ...or create a folder alongside your projector named "xtras" and place a copy in there.

                    I had the xtras in the directory with the projector, but not in a folder called 'Xtras'. This is fixed now.

                    So now, with the following script, I have made some progress, in that I am able to copy and paste the file, however, I am having directory saving issues. I have been unable to get the file I am copying to copy to anywhere but the main directory. If anyone has knowledge on how to copy to a different directory that would be great, particularly copying to a flash drive in Mac OS X ('bb' is the name of the flash drive in the script below). Here is my code:

                    • 7. Re: Copy/Save file to flash drive
                      Level 7
                      > I have been unable to get the file I am copying to copy to anywhere but the
                      > main directory.

                      Can you explain what you mean by "main directory"? Are you perhaps
                      referring to the root of the Flash drive, or the same directory that
                      your Director movie resides in?

                      For some reason you removed the assignment of the return code from the
                      copy method. That's unfortunate as it will usually contain useful
                      information about /why/ an operation failed if it did so.
                      --
                      on mouseUp me
                      OK = baCopyFileProgress(_movie.path & "480p.mov",
                      "/Volumes/bb/480p.mov", "IfNewer", "Copying Movie to disk...", "Cancel", 0)
                      alert OK
                      end

                      • 8. Copy/Save file to flash drive
                        Charles Simonson Level 1
                        By main directory, I mean the directory where the director project resides. I would like to copy a movie from this directory to the root of the flash drive.

                        I updated the code with yours, and now when I run the movie, it gives me an error stating:

                        Script error: String expected
                        Alert OK
                        5

                        If I adjust the code so that it copies the file from the project's directory and pastes it into the same, then the file will copy with the progress bar and after the copy is complete it gives me the same error message as above, only with a '0' instead of a 5.

                        Thank you for your continued help and support.
                        • 9. Re: Copy/Save file to flash drive
                          Level 7
                          > By main directory, I mean the directory where the director project resides. I
                          > would like to copy a movie from this directory to the root of the flash drive
                          > directory.

                          I'm still not understanding you. You want to copy a file from the
                          directory where the projector is, or a sub-directory?
                          If you want to copy from a sub-directory, try something like:
                          --
                          on mouseUp me
                          tSource = "@/movies/480p.mov"
                          tDest = "/Volumes/bb/480p.mov"
                          OK = baCopyFileProgress(tSource, tDest, "IfNewer", "Copying Movie to
                          disk...", "Cancel", 0)
                          if OK <> 0 then alert string(OK)
                          end

                          > I updated the code with yours, and now when I run the movie, it gives me an
                          > error stating:
                          > Script error: String expected
                          > Alert OK
                          > 5

                          My mistake. I assumed that when you use 'alert' whatever you are
                          alerting is auto-cast to a string. Try the above instead.

                          > If I adjust the code so that it copies the file from the projects directory
                          > and pastes it into the same, then the file will copy with the progress bar and
                          > after the copy is complete it gives me the same error message as above, only
                          > with a '0' instead of a 5.

                          If you look in the docs for Buddy API, 0 means the operation succeeded
                          and 5 means "Couldn't create directory for Dest file" (suggesting your
                          destination path is incorrect)
                          Since you already use Buddy API I suggest you use a combination of
                          baDiskList() and baDiskInfo(disk, "type") to determine which is your
                          Flash drive and then use that disk as your root for copying.
                          For example:
                          on mouseUp me
                          lDisks = baDiskList()
                          lTargets = []
                          repeat with aDisk in lDisks
                          if baDiskInfo(aDisk, "type") = "Removable" then
                          -- found (potential) target
                          lTargets.append(aDisk)
                          end if
                          end repeat
                          case count(lTargets) of
                          0: -- no removable drives available to copy to
                          alert "Drive not found"
                          1:
                          tSource = "@/movies/480p.mov"
                          tDest = lTargets[1] & "480p.mov"
                          me.mCopyFile(tSource, tDest)
                          otherwise:
                          -- more than one removable drive available
                          -- you'll need to create a routine to determine
                          -- which one you want to copy to, or present the user with
                          -- a selection they can choose from
                          end case
                          end

                          on mCopyFile me, aSource, aDestination
                          OK = baCopyFileProgress(aSource, aDestination, "IfNewer", "Copying
                          Movie to disk...", "Cancel", 0)
                          if OK <> 0 then alert string(OK)
                          end
                          • 10. Re: Copy/Save file to flash drive
                            Charles Simonson Level 1
                            The source file that I want to copy can be anywhere, be it in the projector directory or a subfolder. I am the only one who will run this projector so the file organization doesn't need to be totally clean. I think the only problem I am having right now is just how to put the code in so that it writes to the flash drive?

                            As you stated and from the error messages, it appears that the script is unable to find my flash drive. Most likely this is just an error on my part with the code I have written telling Director the path to my flash drive. So I think my only question now is just how do I write the path so that it copies the file to my flash drive? If any one knows how to write the code for directing to a path with Mac OS X, it would be very helpful. All the examples I have seen use Windows as the OS, and it does not appear that Director is looking for the path structure that the Mac OS X command line uses.

                            I also pasted the secondary code into the movie, but received the same error message that I got for the first code you posted. BTW, where can I find what the error message codes mean? With your latest code and I am now getting a '1' response. Thanks for you continued patience.
                            • 11. Re: Copy/Save file to flash drive
                              Level 7
                              > With your latest code and I am now getting a '1' response.

                              1 means your source file path is invalid. I posted that example in case
                              you wanted to copy from a sub-directory (in the case that I posted, a
                              folder named "movies" specifically).
                              Buddy API error codes are in the docs. I don't know what form the docs
                              take on a Mac - mine is a Windows .hlp file
                              The second block I posted /should/ take care of locating your Flash
                              drive *without* using Unix-style paths (which may be tripping up Buddy API).
                              To copy a file named "480p.mov" from your source folder to the first
                              removable drive found try the following:
                              --
                              on mouseUp me
                              lDisks = baDiskList()
                              lTargets = []
                              repeat with aDisk in lDisks
                              if baDiskInfo(aDisk, "type") = "Removable" then
                              -- found (potential) target
                              lTargets.append(aDisk)
                              end if
                              end repeat
                              case count(lTargets) of
                              0: -- no removable drives available to copy to
                              alert "Drive not found"
                              1:
                              tSource = _movie.path & "480p.mov"
                              tDest = lTargets[1] & "480p.mov"
                              me.mCopyFile(tSource, tDest)
                              otherwise:
                              -- more than one removable drive available
                              -- you'll need to create a routine to determine
                              -- which one you want to copy to, or present the user with
                              -- a selection they can choose from
                              tFolder = baGetFolder(lTargets[1], "Select a folder to copy to:",
                              0, "Choose folder", -1, -1)
                              if (tFolder = EMPTY) then exit
                              tSource = _movie.path & "480p.mov"
                              tDest = tFolder & "480p.mov"
                              me.mCopyFile(tSource, tDest)
                              end case
                              end

                              on mCopyFile me, aSource, aDestination
                              OK = baCopyFileProgress(aSource, aDestination, "IfNewer", "Copying
                              Movie to disk...", "Cancel", 0)
                              if OK <> 0 then alert string(OK)
                              end
                              • 12. Copy/Save file to flash drive
                                Charles Simonson Level 1
                                Brilliant!!!

                                Sean, you're the man! A big THANK YOU to you and every one else for their help on this issue.

                                Long live Director and these forums.