Is there an easy way to get the current path?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
hiddencode
Posts: 6
Joined: Tue Feb 26, 2008 9:13 am

Is there an easy way to get the current path?

Post by hiddencode » Thu Apr 17, 2008 1:41 am

As a new user to RunRev, I'm pretty frustrated on getting the folder path where my application / stack file is located.

In RunRev, if an application has to load an external text file which resides in the same directory with it, there's a "default folder" property returns the folder path containing the application, which can be used for location reference. Unfortunately, this property works in different ways between a standalone application and development environment, as described by RunRev dictionary:

When you start up the application directly, the defaultFolder is set to the folder containing the application. If you're using the development environment, this is the folder containing Revolution; if you're using a standalone application, this is the folder containing that standalone. (On OS X systems, the defaultFolder is set to the folder that contains the application bundle.)

Is a value of "the folder containing Revolution" useful for anything? On OS X, who needs the path "/Applications/Revolution Studio/2.9.0-gm-1"?

In the above case, you have to use 2 different paths, one for development and one for the standalone (don't forget to change it and save it before creating a standalone. And don't forget to change it back if the development process has to go on). Obviously this is not a effective workaround. So I had spent some time searching on Web and found the following script:

Code: Select all

function getDefaultFolder
	set the itemDelimiter to "/"
	get the filename of this stack
	return item 1 to -2 of it
end getDefaultFolder
It works. But unfortunately again, it doesn't work on standalone applications running on OS X. As described by RunRev dictionary:

On OS X systems ... The filename of stackproperty reports the location of the application inside the bundle, not the bundle's location ... the filename of the application's main stack might be "/Volumes/Disk/MyApp.app/Contents/MacOS/MyApp".

Is it hard to have a property / function, working in both development and standalone environment, crossplatformly, returning the folder path containing ones own application (NOT Revolution)? Absolutely not. In Macromedia Director, a simple syntax "the moviePath" does the job perfectly. In RunRev, of course you can write a script to solve the problem. The point is, this shouldn't have been a problem.

paul_gr
Posts: 319
Joined: Fri Dec 08, 2006 7:38 pm

Post by paul_gr » Thu Apr 17, 2008 3:10 am

Try something like:

put the long name of this stack


Paul -- another frustrated Director developer.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Thu Apr 17, 2008 4:11 am

With a slight modification to the handler you posted you can get what you are after assuming the stack whose filename you use is used to build the executable or is in the same folder as the stack used to build the executable. You just need to check if the stack filename contains a reference to an OS X bundle. Try this:

Code: Select all

function getDefaultFolder 
   set the itemDelimiter to "/" 
   put the effective filename of this stack into theFolder # 'effective' in case 'this stack' is a substack
   put item 1 to -2 of theFolder into theFolder # Strip off filename
   if the platform is "MacOS" and theFolder contains ".app/Contents/MacOS" then
      delete item -3 to -1 of theFolder
   end if
   return theFolder
end getDefaultFolder
Last edited by trevordevore on Thu Apr 17, 2008 2:15 pm, edited 1 time in total.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

hiddencode
Posts: 6
Joined: Tue Feb 26, 2008 9:13 am

Post by hiddencode » Thu Apr 17, 2008 10:21 am

Hi, Trevor,

I just learned a new syntax from your code (the effective filename of this stack). Thanks a lot.

By the way, a "s" is missed after "Content". :wink:


Paul,

Bad news: There're at least 2 frustrated Director developers in this thread.
Good news: We are not alone.
Tri-Trick Team
www.tri-trick.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Thu Apr 17, 2008 2:44 pm

Coming from another environment to Revolution can be frustrating at times. I decided to use Revolution for a project a number of years back when I had always used Director for that type of application before. Getting my head around the Revolution philosophy took a while but I do find it an incredibly powerful tool now.

I recently released an application framework to help ease the pain of creating applications in Revolution which I believe is useful for both new and experienced users alike. If you were using the framework you could get your root application folder using the "application folder" property:

application folder - The path of the folder containing the applica-
tion executable (folder property. This is always the application folder for your application regardless of whether you are running in the IDE or not.

It's free to use so maybe take a look and see if it would be helpful.

http://www.bluemangolearning.com/developer/revolution/
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

hiddencode
Posts: 6
Joined: Tue Feb 26, 2008 9:13 am

Post by hiddencode » Fri Apr 18, 2008 5:28 am

Trevor,

It's really helpful. =)
Tri-Trick Team
www.tri-trick.com

asayd
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Mon Apr 10, 2006 7:02 pm
Contact:

Post by asayd » Thu Apr 24, 2008 9:04 pm

Coming into this late, but hope I can add some light.

When you create a standalone app for Mac OS X, the folder that contains the .app file is automatically the defaultfolder, IF you never set the defaultFolder in your code. I usually do something like this in my preOpenStack or openStack handler for my mainstack:

Code: Select all

on openStack
  if the environment is "development" then 
    setDefaultFolder
  else
   # do nothing; default folder is automatically the app's enclosing folder
  end if
end openStack

on setDefaultFolder
  get the filename of this stack
  set the itemdelimiter to slash
  set the defaultfolder to item 1 to -2 of it
end setDefaultFolder
So it's a case where you can try too hard to find a solution. ;-)

Devin
Devin Asay
Learn to code with LiveCode University
https://livecode.com/store/education/

hiddencode
Posts: 6
Joined: Tue Feb 26, 2008 9:13 am

Post by hiddencode » Sun Apr 27, 2008 10:34 pm

It's never too late. I'm going to try your code immediately.

Thanks a ton. :wink:
Tri-Trick Team
www.tri-trick.com

Post Reply