Re: Get script's folder from within the script
Re: Get script's folder from within the script
- Subject: Re: Get script's folder from within the script
- From: Nicola Vitacolonna <email@hidden>
- Date: Sun, 27 Dec 2009 21:47:07 +0100
> What is the purpose of making it a property?
After pondering over it, I think ASUnit provides a (maybe borderline) example. To make a test case, you have to inherit from ASUnit, e.g.,
property parent : load script file ((path to scripts folder from user domain as string) & "Libraries:ASUnit.scpt")
That's fine as long as ASUnit.scpt is kept in a standard location. Now, suppose that you want your project to be self-contained by putting ASUnit.scpt inside your project folder, e.g., to support automatic building and testing or simply because you want everything in one folder. As far as I understand, you now must specify its absolute path in the source code, and modify the source code if the project is moved to a different location, because something like
property myFolder : folder of file (path to me) of application "Finder"
property parent : load script file (myFolder as text & "ASUnit.scpt")
or, even worse,
set myFolder to the folder of file (path to me) of application "Finder"
property parent : load script file (myFolder as text & "ASUnit.scpt")
obviously won't work. That's why I was wondering whether this alternative can be a better solution:
property myFolder : folder of file (document 1's path as POSIX file) of application "Finder"
property parent : load script file (myFolder as text & "ASUnit.scpt")
In this case, if the project's location changes, the test files need not be changed, but just re-compiled (though this is not a problem - they may be compiled on-the-fly).
Probably there are more significant use cases, but I hope that the bottom line is clear: sometimes it is necessary (or preferable) to combine inheritance from script libraries with location-independence, but this seems hard to achieve.
Nicola
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden