[comp.sys.mac.hypercard] How do I get the pathname?

geoff@pmafire.UUCP (Geoff Allen) (08/19/89)

OK, I give up!  Can someone answer my question?

In _The HyperCard Developer's Guide_, Danny Goodman suggests creating an
"Installer" stack, whose purpose is to install a button for your stack
on the user's Home Card.  "Good idea!" says I and I try to do it.  He
gives some pseudocode for his installation routine and says it's very
simple to do.  He says in the pseudocode something like "assemble
pathnames" and promises to explain in more detail in Chapter 5.  I can
find nothing on the subject in Chapter 5.  The index, under "pathnames,"
only lists pages in the area of the discussion mentioned above.

I also checked _HyperTalk_ by Lon Poole.  Nothing on pathnames.

I scoured the Help stacks looking for something.  No luck.

So.

How do I get the pathname to stack x (or the current stack) from within
a script.  I can always just put my button on the user's Home Card and
let HyperCard ask him "Where is stack x" when he trys to go there, since
Hypercard will then add the necessary line to the "Look for stacks
in..." card.  But this seems clumsy, and I want to be a little slicker
and more transparent to the user.

Any help will be greatly appreciated.

-- 
Geoff Allen - WINCO Computer Process Engineering
------------------------------------------------------------------------------
...{uunet|bigtex}!pmafire!geoff  |  Disclaimer:  WINCO doesn't believe in Macs,
...ucdavis!egg-id!pmafire!geoff  |  so of course these are my own views.

Athos@cup.Portal.com (Rick Eames) (08/21/89)

In article <716@pmafire.UUCP> geoff@pmafire.UUCP (Geoff Allen) writes:
> How do I get the pathname to stack x (or the current stack) from within
> a script.

I think for the current stack "The Long Name of This Stack" gives you the 
pathname to the current stack.  You can then add that path to the Home 
stack card "Stacks" and, this is important, GetHomeInfo after the call to 
update all of the globals.

Rick Eames

stone@grumpy.cs.unm.edu (Andrew Stone) (08/22/89)

In article <716@pmafire.UUCP> geoff@pmafire.UUCP (Geoff Allen) writes:
>
>OK, I give up!  Can someone answer my question?
>How do I get the pathname to stack x (or the current stack) from within
>a script.

Try this one-liner anywhere, include the function trim somewhere handy:

 put trim(the long name of this stack) into source  --get full pathname

function trim name
  delete char 1 to (the length of ("stack" && quote)) of name
  delete last char of name
  return name
end trim

This is useful for copying a stack where you need the whole pathname, but
not the word "stack" or the quotes surrounding what you get back from the
long name function.

andrew

||<<++>>||<<-->>||<<==>>||<<++>>||<<??>>||<<++>>||<<-->>||<<==>>||<<++>>||
!!	   Andrew Stone	            !!        the fictive milieu of	!!
!!         stone@rye.cs.unm.edu	    <> 	      contemporary society!	!!
||<<++>>||<<-->>||<<==>>||<<++>>||<<??>>||<<++>>||<<-->>||<<==>>||<<++>>||

fwb@demon.siemens.com (Frederic W. Brehm) (08/22/89)

In article <716@pmafire.UUCP> geoff@pmafire.UUCP (Geoff Allen) writes:
... lots of frustration deleted ...
>How do I get the pathname to stack x (or the current stack) from within
>a script.

function whereStack -- returns the folder in which this stack lives
  -- The value of this function is the the same as the contents of
  -- the "Where:" field in "Stack Info..." under the "Objects" menu.
  
  -- second word of the long name of this stack is
  --   quote & FOLDER & short name of this stack & quote
  put second word of the long name of this stack into Name
  
  -- extract FOLDER from Name
  return char 2 to length(Name) - length(short name of this stack) - 1 of Name
  
end whereStack

ba0k+@andrew.cmu.edu (Brian Patrick Arnold) (08/22/89)

This sample HyperTalk code may be of some use - I use these all the time.  Make sure you really need
to use these and use them smartly because Mac users should not to have to deal with file paths.
If you want the path without the ending colon, simply "delete last char of <foo>" after calling
"put PathOnly(<bigfoo>) into <foo>" where <foo> and <bigfoo> are your containers.
PathFromStackName is the handler you need, I think.


-------------------------------------------------
-- Handlers for extracting path and file names --
-------------------------------------------------

FUNCTION PathOnly aFileName

  -- return the path only of a given valid Mac OS file path name
  -- algorithm: if contains a path, strip end characters to last colon

  IF HasPath(aFileName) THEN
    REPEAT until IsPath(aFileName)
      delete last char of aFileName
    END REPEAT
  ELSE put empty into aFileName
  RETURN aFileName
END PathOnly

FUNCTION NameOnly aFileName

  -- return the name only of a given valid Mac OS file path name
  -- algorithm: if contains a path, push end chars into container
  --   and delete end chars to last colon - container should then be name only

  IF HasPath(aFileName) THEN
    put empty into theName
    REPEAT until IsPath(aFileName)
      put last char of aFileName before theName
      delete last char of aFileName
    END REPEAT
  ELSE put aFileName into theName
  RETURN theName
END NameOnly

FUNCTION HasPath aFileName
  RETURN (offset(":",aFileName) <> 0)
END HasPath

FUNCTION IsPath aFileName
  RETURN (last char of aFileName = ":")
END IsPath

FUNCTION PathFromStackName aStackName

  -- given a long name of a stack (if empty then use current stack name),
  -- extract the path.  Cake.

  IF aStackName is empty
  THEN put the long name of this stack into aStackName
  delete first word of aStackName -- remove word "Stack"
  delete first char of aStackName -- remove open quote
  delete last char of aStackName  -- remove end quote
  RETURN PathOnly(aStackName)
END PathFromStackName

-------------------------------------------------

- Brian