Re: Path To commands
Re: Path To commands
- Subject: Re: Path To commands
- From: Philippe Gruchet <email@hidden>
- Date: Wed, 8 Jan 2003 07:37:19 +0100
Should we consider this tell block [no break] below concerned by the
"respect to the Startup Disk special folder" ?
tell application "Finder" to make at (path to "docs" as alias) with
properties {name:{"foo"}, file type:"ttro", file creator:"ttxt"} new
file
What do you think about this line?
From Gary Lists:
I think it's beautiful. ;)
Thanks for your admiring aesthetic contemplation :-)
Nearly as "compact" and that _seems_ to be what the cautionary note
suggested, as I understood it.
You did right. I like this kind of short-cuts -- as joke (isn't it an
AS coercion... :-)
** A bit in-depth **
If you feel uncertain about portability, then set some variable to
'path to "docs" as alias' then include that in the tell line.
It's what I sent in a previous post:
-- ==============================
set theDest to path to "docs" as alias
tell app "Finder" to make at theDest with properties {name:{"foo"},
file type:"ttro", file creator:"ttxt"} new file
-- > result: same as the command line above
-- ==============================
However, a 'set some variable' statement is always handled by the host
application, the app that runs the script.
(From within a script editor, a variable is initialized in the editor's
data memory allocation.)
So, by default:
set theDest to path to "docs" as alias
is always an implicit tell block:
tell current application -- that can be (1)
path to "docs" as alias
end tell
(1) tell me to path to "docs" as alias
In other words, since the goal is 'to avoid unnecessary terminology
conflicts' (see below), we have to distinguish which is the current
application from the target application:
tell me to set theDest to path to "docs" as alias --> the current app
tell app "Finder" to make at theDest new file --> the target app
This is a very important point. If ignored, it can be the source of
many encountered errors in our scripts.
** References **
In the very recent (related) thread "Moving files from desktop to User
folders" I asked Paul B. to offer some more insight into this very
issue. I have a tendency to "just do what he says", as that seems to
work in my favor.
Paul B. answered:
3) Running any Standard Additions inside an application tell should
be avoided when not necessary (sometimes it's very necessary to use
them in tell blocks, especially 'display dialog') to avoid
unnecessary terminology conflicts. In particular 'file'. 'file' is
used by AppleScript, Standard Additions (e.g. 'open for access'),
notoriously the Finder, and also notoriously Outlook Express and
Entourage, to mean very different things. The application's
terminology always rules, which prevents you using the same term for
an osax or AppleScript meaning.
From what he says, I am now doing all of my Path To setting (and most
other stuff too) outside any tell block, then referencing it inside
the tell block. It does make some logical sense to me, even without
any errors.
HTH, Philippe
Helps a lot Gary! A lot of us I guess.
Kind regards,
Philippe Gruchet/SVM Mac
VNU Publications France
http://svmmac.vnunet.fr
_______________________________________________
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.