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 ?
What is meant by "home"? There is a
Get ( DocumentPath )
And other "paths"...
Sent from miPhone
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
where any variable that defines /Macintosh HD/Users/Peter/ (that is the real user home on MacOS) ?
You can get the current user's Home folder by chopping off the last part of the result of DocumentsPath, eg like so
d = Get ( DocumentsPath ) ;
pos = Position ( d ; "/" ; 1 ; PatternCount ( d ; "/" ) - 1 )
Replace ( d ; pos ; Length ( d ) - pos ; "" )
can I do this in a calculation or does it have to be in a script ?
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.
mmmhhh I tried in a calculation and it is telling me on pos: Error: the calculation field cannot be found
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
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.)
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 ( [
oops - didn't mean to replicate your answer, more or less.
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.
Retrieving data ...