RE: opening grandparent folder.... (was opening parent folder....)
RE: opening grandparent folder.... (was opening parent folder....)
- Subject: RE: opening grandparent folder.... (was opening parent folder....)
- From: "fearghal" <email@hidden>
- Date: Wed, 27 Feb 2002 14:21:46 -0800
thanks everyone for all the help - lifesavers the lot of you!
f
-----Original Message-----
From: email@hidden
[
mailto:email@hidden]On Behalf Of Kai Edwards
Sent: Wednesday, February 27, 2002 1:07 PM
To: email@hidden
Cc: fearghal
Subject: Re: opening grandparent folder.... (was opening parent
folder....)
on Tue, 26 Feb 2002 11:58:22 -0800, "fearghal" <email@hidden>
wrote:
>
i have a folder called "INSTALLER" and inside that i have a folder called
>
"SCRIPTS", inside scripts i need to have an applescript that will open the
>
folder "INSTALLER"... to make matters complicated, the folder will not
>
always be called "INSTALLER" - it may have a different name and also the
>
location of the folder may vary.. this means that i have to get the path
and
>
the name of the folder dynamically at the start of the script and then use
>
them to open the folder.
I see you've already had some excellent advice about this, fearghal - so
this note is just in case you haven't yet got quite what (I think) you're
after.
As you now probably realise, you can work upwards from your script (as long
as it's saved as an application [1]) through your filing hierarchy.
The 'path to me' function locates the script application. You can then use
either AppleScript's 'text item delimiters' or the Finder's 'container'
terminology to specify any items further up the hierarchy.
By setting AppleScript's text item delimiters to ":", you can identify each
individual item in the path to the application. So you can remove items at
the end of the path by using a phrase like 'items 1 thru -2'.
In case you're not already familiar with the concept of indexed items:
item 1 = the first item of a list
item 2 = the second item of a list
item 3 = the third item (and so on...)
Conversely:
item -1 = the last item of a list
item -2 = the second-to-last item of a list
item -3 = the third-to-last item (and so on...)
So "items 1 thru -2" actually means: every item from the first to the
second-to-last".
As I understand it, your file/folder hierarchy goes something like this:
HARD DISK -> ANY OTHER FOLDERS -> INSTALLER (folder) -> SCRIPTS (folder) ->
SCRIPT (file)
Or, expressed as a path:
"HARD DISK:ANY OTHER FOLDERS:INSTALLER:SCRIPTS:SCRIPT"
So, if you want the SCRIPT to open the INSTALLER folder, the relationship of
folder to script is more like 'grandparent' than 'parent'.
Because of this, to identify the path to the INSTALLER folder (from the path
to the script), you'll need to use something like "items 1 thru -3" - which
should give you the path:
"HARD DISK:ANY OTHER FOLDERS:INSTALLER"
-- which is what I believe you may be after.
A script that uses 'text item delimiters' to truncate a path might therefore
look something like this:
------------------------------------------------
set myFile to path to me as string
set {TID, text item delimiters} to {text item delimiters, ":"}
set myGrndFldr to myFile's text items's items 1 thru -3 as string
set text item delimiters to TID
tell application "Finder"
activate
open alias myGrndFldr
end tell
------------------------------------------------
Alternatively, using the Finder's 'container' terminology, a simpler way to
open the script's grandparent folder might go something like this:
------------------------------------------------
set myFile to path to me
tell application "Finder"
activate
open myFile's container's container
end tell
------------------------------------------------
If I've laboured any point unnecessarily, please forgive me. I just wanted
to make sure you get the results I suspect you're hoping for... :)
HTH
Kai
------------------------------------------------
[1] When the script is saved as a compiled script, the originating
application is AppleScript. When you save it as an application, the script
itself then becomes the originating application.
--
**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.