10 Replies Latest reply on Jan 3, 2017 4:20 AM by beverly

    DocumentPath

    PecCars

      FM offers a variable called DocumentPath that points to the Documents folder. Is there any similar FM variable to point to the home of the user ?

        • 1. Re: DocumentPath
          beverly

          What is meant by "home"? There is a

          Get ( DocumentPath )

           

          And other "paths"...

           

          Sent from miPhone

          • 2. Re: DocumentPath
            PecCars

            Hi Beverly, actually it would be one level above DesktopPath

            if DesktopPath = /Macintosh HD/Users/Peter/Desktop/

            I am looking for

            /Macintosh HD/Users/Peter/Music and

            /Macintosh HD/Users/Peter/Dropbox

            so ...

            where any variable that defines /Macintosh HD/Users/Peter/ (that is the real user home on MacOS) ?

            • 3. Re: DocumentPath
              erolst

              You can get the current user's Home folder by chopping off the last part of the result of DocumentsPath, eg like so

               

              Let (

                d = Get ( DocumentsPath ) ;

                pos = Position ( d ; "/" ; 1 ; PatternCount ( d ; "/" ) - 1 )

                ] ;

                Replace ( d ; pos ; Length ( d ) - pos ; "" )

              )

              • 4. Re: DocumentPath
                PecCars

                can I do this in a calculation or does it have to be in a script ?

                • 5. Re: DocumentPath
                  erolst

                  PecCars wrote:

                   

                  can I do this in a calculation or does it have to be in a script ?

                  Well, it has to be a calculation either way ... it depends on what you want to do.

                   

                  In a script you would typically set a variable to the result of this calc, then pass it to a mechanism that knows what to do with it (so probably not FileMaker itself).

                   

                  If you plan on using AppleScript for file/directory manipulation, be aware that AS has its own environment variables for frequently used paths that you could query.

                  • 6. Re: DocumentPath
                    PecCars

                    mmmhhh I tried in a calculation and it is telling me on pos: Error: the calculation field cannot be found

                    • 7. Re: DocumentPath
                      David Moyer

                      Hi,

                      here's an untested guideline ...

                      let(

                        [

                          path = get(desktoppath);

                          slash = position ( path; "/"; length(path); -2 );

                          parent = left ( path; slash )

                        ];

                        if ( slash > 0; parent; "" )

                      )

                      // includes the last slash

                      (this is best implemented as a custom function, so you can easily reuse it.)

                      (Edited: the -2 is there because Get(DesktopPath) has a trailing slash - we want the next to last occurrence.)

                      • 8. Re: DocumentPath
                        erolst

                        PecCars wrote:

                         

                        mmmhhh I tried in a calculation and it is telling me on pos: Error: the calculation field cannot be found

                        Forgot the opening bracket:

                         

                        Let ( [

                          d = Get ( DocumentsPath ) ;

                          pos = Position ( d ; "/" ; 1 ; PatternCount ( d ; "/" ) - 1 )

                          ] ;

                          Replace ( d ; pos ; Length ( d ) - pos ; "" )

                        )

                        • 9. Re: DocumentPath
                          David Moyer

                          oops - didn't mean to replicate your answer, more or less.

                          • 10. Re: DocumentPath
                            beverly

                            ok, getting the 'value' of a path is one thing. what you can and should do with it is another. keep in mind the caveats posted by others. hosted files will have a different "path" than non-hosted ones. and which paths FMS and/or FMGo and/or WebDirect and/or FMPro sees and can use will be different (permissions). the variable paths are preferable to hard coded ones. reading a path may be slightly different than writing to a path. again, it depends on what you need to do.

                            beverly

                            1 of 1 people found this helpful