Re: Referring to the local hard drive
Re: Referring to the local hard drive
- Subject: Re: Referring to the local hard drive
- From: Joseph Briggs <email@hidden>
- Date: Thu, 04 Jan 2001 07:12:11 -0700
>
>> set saveDelims to AppleScript's text item delimiters
>
>> set AppleScript's text item delimiters to {":"}
>
>> set diskName to text item 1 of (path to startup disk as text)
>
>> set AppleScript's text item delimiters to saveDelims
>
>> log diskName
>
>
> I'm kinda new to this, so I can't be exactly sure if I'm right, but couldn't
>
> you also use:
>
>
>
> set yourVariable to characters 1 thru -2 of (path to startup disk as text)
>
> as text
>
>
>
> This is also independent of the Finder (requires Standard Additions) and
>
> given that the startup disk is every character except the colon of the
>
> startup disk path, this should work. It seems to me, using the delimiters
>
> would be more apt for extracting a second, third, etc., or last text item of
>
> a longer path.
>
>
Why? Either will do. It really makes no big difference, but (path to)
>
requires an osax effort as opposed to pure AppleScript text manipulation
>
(faster, not that that matters here). More to the point, if you happen to be
>
already in an application tell block, (path to) can occasionally be a bit
>
wonky (especially in the Finder).
>
>
--
>
Paul Berkowitz
I agree (about being faster, using AS text manipulation only, and avoiding
placement in a tell block). The first suggestion contained "path to" so I
just figured my suggestion would work just as well with less typing (faster
human processing).
I usually extract a name with a handler that I pass the path to (included
below). (Does calling a handler within a script create a speed bump?) But it
brings up another question, without user interaction, i.e. "choose folder"
(which is an osax function), how else do you get a path to an item without
"path to" or other osax? "alias" maybe? Just curious.
Also, you mention that AS text manipulation is faster without calling an
osax. I imagine you could intuit this simply by the fact that it doesn't
make a call to the SA osax, but I'm kinda hoping you have or know of some
way of measuring the amount of time a process or script takes (more
curiosity). Do you?
>
That works very well, and requires less time and steps. Good thinking! :)
>
Yes, your solution does seem to fit better to this particular task. Thanks
>
for contributing.
>
>
JR
Thanks (wow, kudos on my first post)! I'm glad I signed up for this, I'm
learning a lot.
----
on shortenName(longPath)
set AppleScript's text item delimiters to {":"}
if last character of longPath is ":" then -- it's a folder
set itemCount to (count text items in longPath) - 1 -- last text
item is ""
set shortName to the text item itemCount of longPath
else -- it's a file
set shortName to the last text item of longPath
end if
return shortName
end shortenName
--
Joseph Briggs < email@hidden >
< email@hidden >